Skip to content

Commit

Permalink
INTYGFV-16796: Add catch for FileNotFoundException.
Browse files Browse the repository at this point in the history
  • Loading branch information
cigerhed committed Sep 2, 2024
1 parent 9ca95c1 commit fd2c3b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -52,8 +53,11 @@ public List<RegionNotificationConfig> get() {
new TypeReference<>() {
});
log.info("Integrated Unit Notification was loaded with configuration: {}", integratedUnitNotificationConfig);
} catch (FileNotFoundException e) {
log.warn("File not found: {}. Returning empty configuration.", unitNotificationConfigPath);
return Collections.emptyList();
} catch (Exception e) {
log.info("No Integrated Unit Notification was loaded, returning empty configuration map. Reason: {}", e.getMessage());
log.error("Failed to load Integrated Unit Notification configuration. Reason: {}", e.getMessage(), e);
return Collections.emptyList();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,20 @@ class GetUnitNotificationConfigTest {
@InjectMocks
private GetUnitNotificationConfig getUnitNotificationConfig;


@Test
void shallReturnEmptyListIfPathIsInvalid() {
ReflectionTestUtils.setField(getUnitNotificationConfig, "unitNotificationConfigPath", INVALID_PATH);
final var result = getUnitNotificationConfig.get();
assertTrue(result.isEmpty());
}

@Test
void shallReturnEmptyListIfPathIsMissing() {
ReflectionTestUtils.setField(getUnitNotificationConfig, "unitNotificationConfigPath", null);
final var result = getUnitNotificationConfig.get();
assertTrue(result.isEmpty());
}

@Test
void shallReturnListOfIntegratedUnitNotificationConfig() {
final var expectedRegionNotificationConfig = RegionNotificationConfig.builder()
Expand Down

0 comments on commit fd2c3b4

Please sign in to comment.