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/
8206, the first character, is the Unicode Left-to-Right mark:
8206 Character
You can replace the character with Java regex support, using the character class:
Java Regex matchers
That is, if you believe this test should PASS. If you think, after your analysis, it should FAIL, then the result does FAIL as it stands. The Book class can return a String with stripped Unicode punctuation in its
getPublication()
getter also, using a regexreplaceAll
if you can modify this getter.See also Wikipedia Control characters U+200E. (Made an edit by the way, this is a Control character.)