### Question:
PlainAuthDescriptorGenerator implements AuthDescriptorGenerator { @Override public AuthDescriptor generate(OverridableReadOnlyProperties properties) { String username = properties.getRequiredProperty(USERNAME_PROPERTY_KEY); String password = properties.getRequiredProperty(PASSWORD_PROPERTY_KEY); AuthDescriptor authDescriptor = new AuthDescriptor(new String[]{"PLAIN"}, new PlainCallbackHandler(username, password)); return authDescriptor; }  @Override AuthDescriptor generate(OverridableReadOnlyProperties properties); static final String USERNAME_PROPERTY_KEY; static final String PASSWORD_PROPERTY_KEY; }### Answer:
@Test public void generate_username_missing() throws Exception { expectedException.expect(IllegalStateException.class); Properties props = new Properties(); props.setProperty(PlainAuthDescriptorGenerator.PASSWORD_PROPERTY_KEY, "password"); generator.generate(new OverridableReadOnlyPropertiesImpl(props)); }
@Test public void generate_password_missing() throws Exception { expectedException.expect(IllegalStateException.class); Properties props = new Properties(); props.setProperty(PlainAuthDescriptorGenerator.USERNAME_PROPERTY_KEY, "username"); generator.generate(new OverridableReadOnlyPropertiesImpl(props)); }
@Test public void generate() throws Exception { Properties props = new Properties(); props.setProperty(PlainAuthDescriptorGenerator.USERNAME_PROPERTY_KEY, "username"); props.setProperty(PlainAuthDescriptorGenerator.PASSWORD_PROPERTY_KEY, "password"); AuthDescriptor authDescriptor = generator.generate(new OverridableReadOnlyPropertiesImpl(props)); assertThat(authDescriptor).isNotNull(); assertThat(authDescriptor.getMechs()).isEqualTo(new String[]{"PLAIN"}); assertThat(authDescriptor.getCallback()).isExactlyInstanceOf(PlainCallbackHandler.class); }