DefaultConfigurationReader implements ConfigurationReader { @Override public <T> ConfigurationSettingsUnit read(ConfigurationUnit annotation, Class<T> configurationClass) { requireNonNull(annotation, "annotation is required"); requireNonNull(configurationClass, "configurationClass is required"); List<Configurable> configurations = getConfigurations(annotation); Configurable configuration = getConfiguration(annotation, configurations); String name = configuration.getName(); String description = configuration.getDescription(); Map<String, Object> settings = getSettings(configuration); Class<?> provider = getProvider(configurationClass, configuration); return new DefaultConfigurationSettingsUnit(name, description, provider, Settings.of(settings)); }  @Override ConfigurationSettingsUnit read(ConfigurationUnit annotation, Class<T> configurationClass); @Override ConfigurationSettingsUnit read(ConfigurationUnit annotation);  }
@Test public void shouldReturnNPEWhenAnnotationIsNull() { Assertions.assertThrows(NullPointerException.class, () -> configurationReader.read(null, MockConfiguration.class)); }
@Test public void shouldReturnNPEWhenConfigurationIsNull() { Assertions.assertThrows(NullPointerException.class, () -> { ConfigurationUnit annotation = mock(ConfigurationUnit.class); configurationReader.read(annotation, null); }); }
@Test public void shouldReturnErrorWhenFileDoesNotExist() { Assertions.assertThrows(ConfigurationException.class, () -> { ConfigurationUnit annotation = mock(ConfigurationUnit.class); when(annotation.fileName()).thenReturn("unknown.json"); configurationReader.read(annotation, MockConfiguration.class); }); }
@Test public void shouldReturnAnErrorWhenTheExtensionDoesNotSupport() { Assertions.assertThrows(ConfigurationException.class, () -> { ConfigurationUnit annotation = mock(ConfigurationUnit.class); when(annotation.fileName()).thenReturn("invalid.invalid"); configurationReader.read(annotation, MockConfiguration.class); }); }
@Test public void shouldReturnAnErrorWhenTheFileIsInvalid() { Assertions.assertThrows(ConfigurationException.class, () -> { ConfigurationUnit annotation = mock(ConfigurationUnit.class); when(annotation.fileName()).thenReturn("invalid"); configurationReader.read(annotation, MockConfiguration.class); }); }
@Test public void shouldReturnErrorWhenUnitNameIsNotFind() { Assertions.assertThrows(ConfigurationException.class, () -> { ConfigurationUnit annotation = mock(ConfigurationUnit.class); when(annotation.fileName()).thenReturn("jnosql.json"); when(annotation.name()).thenReturn("unknown"); configurationReader.read(annotation, MockConfiguration.class); }); }
@Test public void shouldReturnErrorWhenClassIsNotFound() { Assertions.assertThrows(ConfigurationException.class, () -> { ConfigurationUnit annotation = mock(ConfigurationUnit.class); when(annotation.fileName()).thenReturn("invalid-class.json"); when(annotation.name()).thenReturn("name-1"); configurationReader.read(annotation, MockConfiguration.class); }); }
@Test public void shouldReturnErrorWhenClassDoesNotMatch() { Assertions.assertThrows(ConfigurationException.class, () -> { ConfigurationUnit annotation = mock(ConfigurationUnit.class); when(annotation.fileName()).thenReturn("invalid-class.json"); when(annotation.name()).thenReturn("name"); configurationReader.read(annotation, MockConfiguration.class); }); }
@Test public void shouldReturnErrorWhenThereIsNotDefaultConstructor() { Assertions.assertThrows(ConfigurationException.class, () -> { ConfigurationUnit annotation = mock(ConfigurationUnit.class); when(annotation.fileName()).thenReturn("invalid-class.json"); when(annotation.name()).thenReturn("name-2"); configurationReader.read(annotation, MockConfiguration.class); }); }
@Test public void shouldReturnErrorWhenThereIsAmbiguous() { Assertions.assertThrows(ConfigurationException.class, () -> { ConfigurationUnit annotation = mock(ConfigurationUnit.class); when(annotation.fileName()).thenReturn("jnosql.json"); configurationReader.read(annotation, MockConfiguration.class); }); }