### Question:
SMSConfigurationFactory { public synchronized ServerGroupConfiguration getSMSConfiguration() { LDAPUser.Type type = LDAPUser.Type.AUTH_ADMIN; for (String group : Arrays.asList("sms", "default")) { try { return parser.getServerConfiguration(group, type); } catch (ServerConfigurationNotFound e) { debug.message("No Server Configuration found for " + group); } catch (ConnectionCredentialsNotFound e) { debug.message("Server Configuration missing " + type.toString() + " credentials for Group " + group); } } throw new IllegalStateException("No server configurations found"); } @Inject  SMSConfigurationFactory(ServerConfigurationFactory parser,
                                   @Named(SessionConstants.SESSION_DEBUG) Debug debug); synchronized ServerGroupConfiguration getSMSConfiguration();  }### Answer:
@Test (expectedExceptions = IllegalStateException.class) public void shouldFailIfNoConfigurationsDefined() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound { given(mockFactory.getServerConfiguration( anyString(), any(LDAPUser.Type.class))) .willThrow(mock(ServerConfigurationNotFound.class)); factory.getSMSConfiguration(); }
@Test public void shouldReturnFirstValidConfiguration() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound { ServerGroupConfiguration first = mock(ServerGroupConfiguration.class); ServerGroupConfiguration second = mock(ServerGroupConfiguration.class); given(mockFactory.getServerConfiguration(anyString(), any(LDAPUser.Type.class))) .willReturn(first) .willReturn(second); ServerGroupConfiguration result = factory.getSMSConfiguration(); assertThat(result).isEqualTo(first); }