我想测试我的addSomething方法,我已经创建了如下所示的setUp方法:
@Before
public void setUp() throws Exception {
activitiesService = new ActivitiesService(databaseControllerMock);
when(databaseControllerMock.get(anyString(), any())).thenReturn(item);
when(item.getJSON(anyString())).thenReturn("test");
}
在这种情况下,我有以下错误消息:
com.fasterxml.jackson.core.JsonParseException:无法识别的令牌'测试':期待' null',' true',' false&# 39;或NaN
所以我改变了:
when(item.getJSON(anyString())).thenReturn("true");
在这种情况下,我遇到了这种错误:
com.fasterxml.jackson.databind.exc.MismatchedInputException:无法从VALUE_TRUE标记中反序列化java.util.ArrayList
的实例
在[来源:(字符串)"真&#34 ;; line:1,column:1]
所有这些都与我方法的这一部分有关:
try {
Item item = dbService.get(tableName, Collections.singletonList(primaryKey));
String measurementsJSON = item.getJSON("measurements");
String mealsJSON = item.getJSON("meals");
String trainingsJSON = item.getJSON("trainings");
ObjectMapper objectMapper = new ObjectMapper();
List<Measurement> measurements = objectMapper.readValue(measurementsJSON, new TypeReference<List<Measurement>>() {
});
List<Meal> meals = objectMapper.readValue(mealsJSON, new TypeReference<List<Meal>>() {
});
List<Training> trainings = objectMapper.readValue(trainingsJSON, new TypeReference<List<Training>>() {
});
DbService和Item是Mocks。有人可以帮我解决这个问题吗?