EncryptorService { public void initialize(String masterPassword) { checkNotNull(masterPassword, "Must provide a master password"); checkArgument(!masterPassword.isEmpty(), "Must provide a master password"); synchronized (configurationLock) { checkState(!isInitialized(), "Cannot initialize encryption settings more than once"); checkState(isConfigured(), "Must configure encryption settings before initializing"); EncryptorSettings encryptorSettings = settingsService.retrieve().getEncryptorSettings(); if (!encryptorSettings.validateMasterPassword(masterPassword)) { throw new InvalidMasterPasswordException(); } encryptorProviderService.setEncryptor(new Encryptor(encryptorSettings, masterPassword)); } } @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 initializeWrongPassword() { EncryptorSettings encryptorSettings = EncryptorSettings.newSettings("1234"); settings.set(new Settings(encryptorSettings, false)); thrown.expect(InvalidMasterPasswordException.class); encryptorService.initialize("not-the-same"); }
@Test public void initialize() { EncryptorSettings encryptorSettings = EncryptorSettings.newSettings("1234"); settings.set(new Settings(encryptorSettings, false)); assertFalse(encryptorService.isInitialized()); encryptorService.initialize("1234"); verify(encryptorProviderService).setEncryptor(any(Encryptor.class)); assertTrue(encryptorService.isInitialized()); }