ConfigurationPasswordChecker { public void assertPasswordCorrect(String password) { if (!isPasswordSet()) { throw new IllegalStateException("'" + updateConfigPasswordKey + "' is not set."); } if (!isPasswordCorrect(password)) { throw new IllegalStateException("Wrong password for '" + updateConfigPasswordKey + "'."); } } ConfigurationPasswordChecker(ConfigurationRegistry configurationRegistry, String updateConfigPasswordKey); boolean isPasswordCorrect(String password); void assertPasswordCorrect(String password); boolean isPasswordSet();  }
@Test public void testUpdateConfigurationWithoutPasswordSet() throws IOException { try { configurationPasswordChecker.assertPasswordCorrect(null); fail(); } catch (IllegalStateException e) { assertEquals("'configuration.password' is not set.", e.getMessage()); } }
@Test public void testSetNewPasswordViaQueryParamsShouldFail() throws IOException { configuration.addConfigurationSource(SimpleSource.forTest(passwordKey, "")); try { configurationPasswordChecker.assertPasswordCorrect(""); configuration.save(passwordKey, "", null); fail(); } catch (IllegalArgumentException e) { assertEquals("Config key 'configuration.password' does not exist.", e.getMessage()); } }
@Test public void testUpdateConfigurationWithoutPassword() throws IOException { configuration.addConfigurationSource(SimpleSource.forTest(passwordKey, "pwd")); try { configurationPasswordChecker.assertPasswordCorrect(null); fail(); } catch (IllegalStateException e) { assertEquals("Wrong password for 'configuration.password'.", e.getMessage()); } }
@Test public void testUpdateConfigurationWithPassword() throws IOException { configuration.addConfigurationSource(SimpleSource.forTest(passwordKey, "pwd")); configurationPasswordChecker.assertPasswordCorrect("pwd"); }