Fix mock tests

Former-commit-id: 8ecd9fcbda
This commit is contained in:
Tour
2025-12-05 03:42:36 +01:00
parent 2ff7aa6027
commit 96cc09c387
11 changed files with 105 additions and 22 deletions

View File

@@ -30,14 +30,14 @@ class NotificationServiceTest {
@Test
@DisplayName("Should reject invalid SMTP configuration format")
void testInvalidSMTPConfiguration() {
// Missing parts
// Missing parts (only 2 parts total)
assertThrows(IllegalArgumentException.class, () ->
new NotificationService("smtp:incomplete")
);
// Wrong format
// Wrong format (only 3 parts total, needs 4)
assertThrows(IllegalArgumentException.class, () ->
new NotificationService("smtp:only:two:parts")
new NotificationService("smtp:only:two")
);
}

View File

@@ -82,7 +82,7 @@ class ObjectDetectionServiceTest {
}
@Test
@DisplayName("Should initialize successfully with valid model files")
@DisplayName("Should throw IOException when model files exist but OpenCV fails to load")
void testInitializeWithValidModels() throws IOException {
// Create dummy model files for testing initialization
var cfgPath = Paths.get(TEST_CFG);
@@ -94,15 +94,10 @@ class ObjectDetectionServiceTest {
Files.write(weightsPath, new byte[]{0, 1, 2, 3});
Files.writeString(classesPath, "person\ncar\ntruck\n");
// Note: This will still fail to load actual YOLO model without OpenCV
// But it tests file existence check
assertDoesNotThrow(() -> {
try {
new ObjectDetectionService(TEST_CFG, TEST_WEIGHTS, TEST_CLASSES);
} catch (IOException e) {
// Expected if OpenCV not loaded
assertTrue(e.getMessage().contains("Failed to initialize"));
}
// When files exist but OpenCV native library isn't loaded,
// constructor should throw IOException wrapping the UnsatisfiedLinkError
assertThrows(IOException.class, () -> {
new ObjectDetectionService(TEST_CFG, TEST_WEIGHTS, TEST_CLASSES);
});
} finally {
Files.deleteIfExists(cfgPath);
@@ -113,10 +108,16 @@ class ObjectDetectionServiceTest {
@Test
@DisplayName("Should handle missing class names file")
void testMissingClassNamesFile() {
assertThrows(IOException.class, () -> {
new ObjectDetectionService("non_existent.cfg", "non_existent.weights", "non_existent.txt");
});
void testMissingClassNamesFile() throws IOException {
// When model files don't exist, service initializes in disabled mode (no exception)
ObjectDetectionService service = new ObjectDetectionService(
"non_existent.cfg",
"non_existent.weights",
"non_existent.txt"
);
assertNotNull(service);
// Verify it returns empty results when disabled
assertTrue(service.detectObjects("test.jpg").isEmpty());
}
@Test