I'm using Hamcrest for asserting in my tests. The below snippet works for other string comparisons, however below statement is failing because of some random character(?) at 0th place in the object value array as shown in attached image below.
assertThat("failure, Publication did not match", book.getPublication(), is("Bloomsbury Publishing"));
Here is the result:
java.lang.AssertionError: failure, Publication did not match
Expected: is "Bloomsbury Publishing"
but: was "Bloomsbury Publishing"
Expected :Bloomsbury Publishing
Actual :Bloomsbury Publishing
If it helps, Book is an extended JPA entity from Product entity where Product has annotation @Inheritance( strategy = InheritanceType.JOINED ).
Product Class
private long id;
private String prodName;
private BigDecimal price;
Book Class
private String genre;
private String author;
private String publication;
In my test data in data.sql I have:
INSERT INTO PRODUCT(ID, PROD_NAME, PRICE) VALUES (1, 'Harry Potter', 200.55);
INSERT INTO PRODUCT(ID, PROD_NAME, PRICE) VALUES (2, 'Chhawa', 450.45);
INSERT INTO PRODUCT(ID, PROD_NAME, PRICE) VALUES (3, 'Chatrapati Shivaji Maharaj', 1000.00);
INSERT INTO PRODUCT(ID, PROD_NAME, PRICE) VALUES (4, 'Asa Mi Asami', 99.99);
INSERT INTO BOOK(ID, GENRE, AUTHOR, PUBLICATION) VALUES (1, 'Contemporary Fantasy', 'J. K. Rollings', 'Bloomsbury Publishing');
INSERT INTO BOOK(ID, GENRE, AUTHOR, PUBLICATION) VALUES (2, 'Action', 'Shivaji Savant', 'Mehta Publishing House');
INSERT INTO BOOK(ID, GENRE, AUTHOR, PUBLICATION) VALUES (3, 'Action', 'Krishanrao Arjun Kelusakar', 'Saraswati Publishing Co.Pvt.Ltd');
INSERT INTO BOOK(ID, GENRE, AUTHOR, PUBLICATION) VALUES (4, 'Comedy', 'Pu La Deshpande', 'SANSKRUTI BOOK HOUSE');
And I'm un-marshling the json returned by @GetMapping(path = "/products/{id}")
like:
ResponseEntity<Book> response = restTemplate.exchange(
productBaseUrl,
HttpMethod.GET,
null,
Book.class);
Book book = response.getBody();
Mysteriously, I get this '\u200E' 8206
unicode character only for ID=1
Here is the link to the whole code base: https://bitbucket.org/tyro_02/demo.cart/