### Question:
DatabaseTypeSetterFactory { public DatabaseTypeSetter get(String databaseType) { List<DatabaseTypeSetter> matchingTypeSetters = registeredTypeSetters.stream() .filter(typeSetter -> containsIgnoreCase(databaseType, typeSetter)) .collect(Collectors.toList()); if (matchingTypeSetters.isEmpty()) { throw new IllegalStateException(MessageFormat.format("No database type setter is defined for type \"{0}\"", databaseType)); } if (matchingTypeSetters.size() > 1) { throw new IllegalStateException(MessageFormat.format("More than one database type setters are defined for type \"{0}\"", databaseType)); } return matchingTypeSetters.get(0); } DatabaseTypeSetterFactory();  DatabaseTypeSetterFactory(List<DatabaseTypeSetter> registeredTypeSetters); DatabaseTypeSetter get(String databaseType);  }### Answer:
@Test void testGetWithNullStringParameter() { DatabaseTypeSetterFactory databaseTypeSetterFactory = new DatabaseTypeSetterFactory(); Assertions.assertThrows(IllegalStateException.class, () -> databaseTypeSetterFactory.get(null)); }
@Test void testGetWithEmptyStringParameter() { DatabaseTypeSetterFactory databaseTypeSetterFactory = new DatabaseTypeSetterFactory(); Assertions.assertThrows(IllegalStateException.class, () -> databaseTypeSetterFactory.get("")); }
@Test void testGetWithCustomRegisteredTypeSettersAndSingleMatch() { List<DatabaseTypeSetter> registeredDatabaseTypeSetters = List.of(new BooleanDatabaseTypeSetter()); DatabaseTypeSetterFactory databaseTypeSetterFactory = new DatabaseTypeSetterFactory(registeredDatabaseTypeSetters); DatabaseTypeSetter resultDatabaseTypeSetter = databaseTypeSetterFactory.get(BOOL_TYPE); Assertions.assertEquals(registeredDatabaseTypeSetters.get(0), resultDatabaseTypeSetter); }
@Test void testGetWithCustomRegisteredTypeSettersWhenNoMatchingTypeSetter() { List<DatabaseTypeSetter> registeredDatabaseTypeSetters = Collections.emptyList(); DatabaseTypeSetterFactory databaseTypeSetterFactory = new DatabaseTypeSetterFactory(registeredDatabaseTypeSetters); Assertions.assertThrows(IllegalStateException.class, () -> databaseTypeSetterFactory.get(BOOL_TYPE)); }
@Test void testGetWithCustomRegisteredTypeSettersWhenMultipleMatchingTypeSetters() { List<DatabaseTypeSetter> registeredDatabaseTypeSetters = List.of(new BooleanDatabaseTypeSetter(), new BooleanDatabaseTypeSetter()); DatabaseTypeSetterFactory databaseTypeSetterFactory = new DatabaseTypeSetterFactory(registeredDatabaseTypeSetters); Assertions.assertThrows(IllegalStateException.class, () -> databaseTypeSetterFactory.get(BOOL_TYPE)); }
@Test void testGetWithDefaultRegisteredTypeSettersWhenMatchingDefaultTypeSetters() { DatabaseTypeSetterFactory databaseTypeSetterFactory = new DatabaseTypeSetterFactory(); DatabaseTypeSetter resultDatabaseTypeSetter = databaseTypeSetterFactory.get(BOOL_TYPE); Assertions.assertTrue(resultDatabaseTypeSetter.getSupportedTypes() .contains(BOOL_TYPE)); resultDatabaseTypeSetter = databaseTypeSetterFactory.get(LONG_TYPE); Assertions.assertTrue(resultDatabaseTypeSetter.getSupportedTypes() .contains(LONG_TYPE)); resultDatabaseTypeSetter = databaseTypeSetterFactory.get(STRING_TYPE); Assertions.assertTrue(resultDatabaseTypeSetter.getSupportedTypes() .contains(STRING_TYPE)); }