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;
|
package com.timeline.user.service;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.timeline.user.dao.SmartCollectionMapper;
|
import com.timeline.user.dao.SmartCollectionMapper;
|
||||||
import com.timeline.user.dto.SmartCollectionDto;
|
import com.timeline.user.dto.SmartCollectionDto;
|
||||||
@@ -67,10 +68,15 @@ class SmartCollectionServiceTest {
|
|||||||
// Given
|
// Given
|
||||||
Map<String, Object> metadata = new HashMap<>();
|
Map<String, Object> metadata = new HashMap<>();
|
||||||
metadata.put("date", LocalDateTime.of(2024, 1, 15, 10, 30));
|
metadata.put("date", LocalDateTime.of(2024, 1, 15, 10, 30));
|
||||||
|
|
||||||
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
||||||
eq(testUserId), eq("DATE"), anyString())).thenReturn(0);
|
eq(testUserId), eq("DATE"), anyString())).thenReturn(0);
|
||||||
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
try {
|
||||||
|
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
// When
|
// When
|
||||||
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
||||||
@@ -89,10 +95,15 @@ class SmartCollectionServiceTest {
|
|||||||
location.put("latitude", 48.8566);
|
location.put("latitude", 48.8566);
|
||||||
location.put("longitude", 2.3522);
|
location.put("longitude", 2.3522);
|
||||||
metadata.put("location", location);
|
metadata.put("location", location);
|
||||||
|
|
||||||
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
||||||
eq(testUserId), eq("LOCATION"), anyString())).thenReturn(0);
|
eq(testUserId), eq("LOCATION"), anyString())).thenReturn(0);
|
||||||
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
try {
|
||||||
|
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
// When
|
// When
|
||||||
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
||||||
@@ -106,10 +117,15 @@ class SmartCollectionServiceTest {
|
|||||||
// Given
|
// Given
|
||||||
Map<String, Object> metadata = new HashMap<>();
|
Map<String, Object> metadata = new HashMap<>();
|
||||||
metadata.put("persons", Arrays.asList("Alice", "Bob"));
|
metadata.put("persons", Arrays.asList("Alice", "Bob"));
|
||||||
|
|
||||||
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
||||||
eq(testUserId), eq("PERSON"), anyString())).thenReturn(0);
|
eq(testUserId), eq("PERSON"), anyString())).thenReturn(0);
|
||||||
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
try {
|
||||||
|
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
// When
|
// When
|
||||||
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
||||||
@@ -124,10 +140,15 @@ class SmartCollectionServiceTest {
|
|||||||
// Given
|
// Given
|
||||||
Map<String, Object> metadata = new HashMap<>();
|
Map<String, Object> metadata = new HashMap<>();
|
||||||
metadata.put("date", LocalDateTime.of(2024, 1, 15, 10, 30));
|
metadata.put("date", LocalDateTime.of(2024, 1, 15, 10, 30));
|
||||||
|
|
||||||
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
when(smartCollectionMapper.existsByUserIdAndTypeAndCriteria(
|
||||||
eq(testUserId), eq("DATE"), anyString())).thenReturn(1);
|
eq(testUserId), eq("DATE"), anyString())).thenReturn(1);
|
||||||
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
try {
|
||||||
|
when(objectMapper.writeValueAsString(anyMap())).thenReturn("{}");
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
// When
|
// When
|
||||||
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
smartCollectionService.processPhotoMetadata(testUserId, "photo123", metadata);
|
||||||
|
|||||||
Reference in New Issue
Block a user