EncryptorService { public void reconfigure(String newMasterPassword) { checkMasterPassword(newMasterPassword); synchronized (configurationLock) { checkState(isConfigured(), "Encryption must be configured to reset the master password"); checkState(isInitialized(), "Encryption must be initialized to reset the master password"); encryptorListener.aboutToChangeEncryptor(); setMasterPassword(newMasterPassword); encryptorListener.encryptorChanged(); } } @Inject  EncryptorService(SettingsService settingsService, EncryptorProviderService encryptorProviderService,
			EncryptorListener encryptorListener); boolean isConfigured(); boolean isInitialized(); void reconfigure(String newMasterPassword); void configure(String masterPassword); void initialize(String masterPassword);  }
@Test public void reconfigure() { encryptorService.configure("1234"); InOrder order = inOrder(encryptorProviderService, settingsService); order.verify(encryptorProviderService).setEncryptor(any(Encryptor.class)); order.verify(settingsService).update(any()); assertTrue(settings.get().getEncryptorSettings().validateMasterPassword("1234")); encryptorService.reconfigure("5678"); order = inOrder(encryptorProviderService, settingsService, encryptorListener); order.verify(encryptorListener).aboutToChangeEncryptor(); order.verify(encryptorProviderService).setEncryptor(any(Encryptor.class)); order.verify(settingsService).update(any()); order.verify(encryptorListener).encryptorChanged(); assertTrue(settings.get().getEncryptorSettings().validateMasterPassword("5678")); }
@Test public void reconfigureBeforeInitialize() { EncryptorSettings encryptorSettings = EncryptorSettings.newSettings("1234"); settings.set(new Settings(encryptorSettings, false)); thrown.expect(IllegalStateException.class); thrown.expectMessage("Encryption must be initialized to reset the master password"); encryptorService.reconfigure("5678"); }
@Test public void reconfigureNull() { thrown.expect(NullPointerException.class); thrown.expectMessage("Must provide a master password"); encryptorService.reconfigure(null); }
@Test public void reconfigureEmpty() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Must provide a master password"); encryptorService.reconfigure(""); }
@Test public void reconfigureInvalid() { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Master password must not have leading or trailing whitespace"); encryptorService.reconfigure(" asdf"); }