我在测试中使用 Hamcrest 进行断言。下面的代码片段适用于其他字符串比较,但是下面的语句由于对象值数组中第 0 位的一些随机字符(?)而失败,如下图所示。
assertThat("failure, Publication did not match", book.getPublication(), is("Bloomsbury Publishing"));
结果如下:
java.lang.AssertionError: failure, Publication did not match
Expected: is "Bloomsbury Publishing"
but: was "Bloomsbury Publishing"
Expected :Bloomsbury Publishing
Actual :Bloomsbury Publishing
如果有帮助,Book 是 Product 实体的扩展 JPA 实体,其中 Product 具有注释 @Inheritance( strategy = InheritanceType.JOINED )。
产品类别
private long id;
private String prodName;
private BigDecimal price;
书类
private String genre;
private String author;
private String publication;
在 data.sql 中的测试数据中,我有:
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');
我正在取消编组返回的 json, @GetMapping(path = "/products/{id}")
例如:
ResponseEntity<Book> response = restTemplate.exchange(
productBaseUrl,
HttpMethod.GET,
null,
Book.class);
Book book = response.getBody();
神秘的是,我'\u200E' 8206
只为 ID=1 得到这个 unicode 字符
这是整个代码库的链接: https ://bitbucket.org/tyro_02/demo.cart/