@Test public void testHighestEncryptionModeWithoutPassword() { try { builder.setEncryptionMethod(HawkBuilder.EncryptionMethod.HIGHEST).build(); fail(); } catch (Exception e) { assertThat(e).hasMessage("Password cannot be null " + "if encryption mode is highest"); } }
@Test public void testPassword() { try { builder.setPassword(null); fail(); } catch (Exception e) { assertThat(e).hasMessage("Password should not be null or empty"); } try { builder.setPassword(""); fail(); } catch (Exception e) { assertThat(e).hasMessage("Password should not be null or empty"); } builder.setPassword("password"); assertThat(builder.getPassword()).isEqualTo("password"); }
@Test public void initWithCallback() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); HawkBuilder.Callback callback = new HawkBuilder.Callback() { @Override public void onSuccess() { assertTrue(true); latch.countDown(); } @Override public void onFail(Exception e) { assertTrue(true); latch.countDown(); } }; builder.setCallback(callback).build(); assertThat(latch.await(LATCH_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS)).isTrue(); }
@Test public void testNoEncrpytionMode() { builder.setEncryptionMethod(HawkBuilder.EncryptionMethod.NO_ENCRYPTION).build(); assertThat(builder.getEncryptionMethod()).isEqualTo(HawkBuilder.EncryptionMethod.NO_ENCRYPTION); }
@Test public void testDefaultEncryptionMode() { assertThat(builder.getEncryptionMethod()).isEqualTo(HawkBuilder.EncryptionMethod.MEDIUM); }
@Test public void testDefaultEncryption() { builder.build(); assertThat(builder.getEncryption()).isInstanceOf(AesEncryption.class); }
@Test public void testDefaultEncoded() { builder.build(); assertThat(builder.getEncoder()).isInstanceOf(HawkEncoder.class); }
@Test public void testCustomParser() { CustomParser parser = new CustomParser(new Gson()); builder.setParser(parser).build(); assertThat(builder.getParser()).isInstanceOf(CustomParser.class); }
@Test public void testDefaultParser() { builder.build(); assertThat(builder.getParser()).isInstanceOf(GsonParser.class); }
@Test public void testCustomStorage() { builder.setStorage(HawkBuilder.newSqliteStorage(context)).build(); assertThat(builder.getStorage()).isInstanceOf(SqliteStorage.class); }
@Test public void testDefaultStorage() { builder.build(); assertThat(builder.getStorage()).isInstanceOf(SharedPreferencesStorage.class); }
@Test public void testCustomLogLevel() { builder.setLogLevel(LogLevel.FULL).build(); assertThat(builder.getLogLevel()).isEqualTo(LogLevel.FULL); }
@Test public void testDefaultLogLevel() { builder.build(); assertThat(builder.getLogLevel()).isEqualTo(LogLevel.NONE); }
@Test public void testHighestEncryptionMethodWithPasword() { builder.setEncryptionMethod(HawkBuilder.EncryptionMethod.HIGHEST).setPassword("test"); assertThat(builder.getEncryptionMethod()).isEqualTo(HawkBuilder.EncryptionMethod.HIGHEST); }