### Question:
ServerConfigurationFactory { public ServerGroupConfiguration getServerConfiguration(String groupName, LDAPUser.Type authType) throws ServerConfigurationNotFound, ConnectionCredentialsNotFound { ServerGroup serverGroup = config.getServerGroup(groupName); ServerInstance instance = config.getServerInstance(groupName, authType); if (serverGroup == null) { throw new ServerConfigurationNotFound(groupName); } if (instance == null) { throw new ConnectionCredentialsNotFound(authType); } return new ServerGroupConfiguration(serverGroup, instance); } @Inject  ServerConfigurationFactory(DSConfigMgr config); ServerGroupConfiguration getServerConfiguration(String groupName, LDAPUser.Type authType);  }### Answer:
@Test (expectedExceptions = ServerConfigurationNotFound.class) public void shouldIndicateInvalidIfServerGroupIsNull() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound { ServerInstance mockInstance = mock(ServerInstance.class); DSConfigMgr mockConfig = mock(DSConfigMgr.class); given(mockConfig.getServerGroup(anyString())).willReturn(null); given(mockConfig.getServerInstance( anyString(), any(LDAPUser.Type.class))).willReturn(mockInstance); ServerConfigurationFactory parser = new ServerConfigurationFactory(mockConfig); parser.getServerConfiguration("", LDAPUser.Type.AUTH_ADMIN); }
@Test (expectedExceptions = ConnectionCredentialsNotFound.class) public void shouldIndicateInvalidIfServerInstanceIsNull() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound { ServerGroup mockGroup = mock(ServerGroup.class); DSConfigMgr mockConfig = mock(DSConfigMgr.class); given(mockConfig.getServerGroup(anyString())).willReturn(mockGroup); given(mockConfig.getServerInstance( anyString(), any(LDAPUser.Type.class))).willReturn(null); ServerConfigurationFactory parser = new ServerConfigurationFactory(mockConfig); parser.getServerConfiguration("", LDAPUser.Type.AUTH_ADMIN); }
@Test public void shouldReturnRequestedServerGroup() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound { String test = "badger"; ServerGroup mockGroup = mock(ServerGroup.class); ServerInstance mockInstance = mock(ServerInstance.class); DSConfigMgr mockConfig = mock(DSConfigMgr.class); given(mockConfig.getServerGroup(test)).willReturn(mockGroup); given(mockConfig.getServerInstance( anyString(), any(LDAPUser.Type.class))).willReturn(mockInstance); ServerConfigurationFactory parser = new ServerConfigurationFactory(mockConfig); parser.getServerConfiguration(test, LDAPUser.Type.AUTH_ADMIN); verify(mockConfig).getServerGroup(test); }
@Test public void shouldReturnInstanceBindDN() throws ConnectionCredentialsNotFound, ServerConfigurationNotFound { DSConfigMgr configMgr = mock(DSConfigMgr.class); ServerGroup serverGroup = mock(ServerGroup.class); given(configMgr.getServerGroup(anyString())).willReturn(serverGroup); ServerInstance mockInstance = mock(ServerInstance.class); given(configMgr.getServerInstance( anyString(), any(LDAPUser.Type.class))).willReturn(mockInstance); given(mockInstance.getAuthID()).willReturn(""); ServerConfigurationFactory parser = new ServerConfigurationFactory(configMgr); String dn = parser.getServerConfiguration("", LDAPUser.Type.AUTH_ADMIN).getBindDN(); verify(mockInstance).getAuthID(); }