@@ -70,9 +70,13 @@ class ImageProcessingServiceTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should handle image download failure gracefully")
|
||||
void testDownloadImageFailure() {
|
||||
// Invalid URL should return null
|
||||
String result = service.downloadImage("invalid-url", 123, 456);
|
||||
void testDownloadImageFailure() throws Exception {
|
||||
// Mock HTTP client to throw exception
|
||||
when(mockHttpClient.sendGetBytes(anyString()))
|
||||
.thenThrow(new java.io.IOException("Connection failed"));
|
||||
|
||||
// Should return null on failure
|
||||
String result = service.downloadImage("http://example.com/image.jpg", 123, 456);
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
@@ -164,7 +168,14 @@ class ImageProcessingServiceTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Should handle database errors during image save")
|
||||
void testDatabaseErrorHandling() throws SQLException {
|
||||
void testDatabaseErrorHandling() throws Exception {
|
||||
// Mock successful HTTP download
|
||||
@SuppressWarnings("unchecked")
|
||||
var mockResponse = mock(java.net.http.HttpResponse.class);
|
||||
when(mockResponse.statusCode()).thenReturn(200);
|
||||
when(mockResponse.body()).thenReturn(new byte[]{1, 2, 3});
|
||||
when(mockHttpClient.sendGetBytes(anyString())).thenReturn(mockResponse);
|
||||
|
||||
when(mockDetector.detectObjects(anyString()))
|
||||
.thenReturn(List.of("object"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user