test(SmartCollectionServiceTest): 添加对JsonProcessingException的处理
Some checks failed
test/timeline-server/pipeline/head There was a failure building this commit
Some checks failed
test/timeline-server/pipeline/head There was a failure building this commit
在测试中为objectMapper.writeValueAsString添加异常处理,确保测试用例能够正确处理可能出现的JsonProcessingException
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.timeline.user.service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.timeline.user.dao.SmartCollectionMapper;
|
||||
import com.timeline.user.dto.SmartCollectionDto;
|
||||
@@ -70,7 +71,12 @@ class SmartCollectionServiceTest {
|
||||
|
||||
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
||||
eq(testUserId), eq("DATE"), anyString())).thenReturn(0);
|
||||
try {
|
||||
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// When
|
||||
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
||||
@@ -92,7 +98,12 @@ class SmartCollectionServiceTest {
|
||||
|
||||
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
||||
eq(testUserId), eq("LOCATION"), anyString())).thenReturn(0);
|
||||
try {
|
||||
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// When
|
||||
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
||||
@@ -109,7 +120,12 @@ class SmartCollectionServiceTest {
|
||||
|
||||
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
||||
eq(testUserId), eq("PERSON"), anyString())).thenReturn(0);
|
||||
try {
|
||||
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// When
|
||||
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
||||
@@ -127,7 +143,12 @@ class SmartCollectionServiceTest {
|
||||
|
||||
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
||||
eq(testUserId), eq("DATE"), anyString())).thenReturn(1);
|
||||
try {
|
||||
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
||||
} catch (JsonProcessingException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// When
|
||||
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
||||
|
||||
Reference in New Issue
Block a user