Beispiel #1
0
 @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");
   }
 }
Beispiel #2
0
  @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");
  }
Beispiel #3
0
  @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();
  }
Beispiel #4
0
 @Test
 public void testNoEncrpytionMode() {
   builder.setEncryptionMethod(HawkBuilder.EncryptionMethod.NO_ENCRYPTION).build();
   assertThat(builder.getEncryptionMethod()).isEqualTo(HawkBuilder.EncryptionMethod.NO_ENCRYPTION);
 }
Beispiel #5
0
 @Test
 public void testDefaultEncryptionMode() {
   assertThat(builder.getEncryptionMethod()).isEqualTo(HawkBuilder.EncryptionMethod.MEDIUM);
 }
Beispiel #6
0
 @Test
 public void testDefaultEncryption() {
   builder.build();
   assertThat(builder.getEncryption()).isInstanceOf(AesEncryption.class);
 }
Beispiel #7
0
 @Test
 public void testDefaultEncoded() {
   builder.build();
   assertThat(builder.getEncoder()).isInstanceOf(HawkEncoder.class);
 }
Beispiel #8
0
 @Test
 public void testCustomParser() {
   CustomParser parser = new CustomParser(new Gson());
   builder.setParser(parser).build();
   assertThat(builder.getParser()).isInstanceOf(CustomParser.class);
 }
Beispiel #9
0
 @Test
 public void testDefaultParser() {
   builder.build();
   assertThat(builder.getParser()).isInstanceOf(GsonParser.class);
 }
Beispiel #10
0
 @Test
 public void testCustomStorage() {
   builder.setStorage(HawkBuilder.newSqliteStorage(context)).build();
   assertThat(builder.getStorage()).isInstanceOf(SqliteStorage.class);
 }
Beispiel #11
0
 @Test
 public void testDefaultStorage() {
   builder.build();
   assertThat(builder.getStorage()).isInstanceOf(SharedPreferencesStorage.class);
 }
Beispiel #12
0
 @Test
 public void testCustomLogLevel() {
   builder.setLogLevel(LogLevel.FULL).build();
   assertThat(builder.getLogLevel()).isEqualTo(LogLevel.FULL);
 }
Beispiel #13
0
 @Test
 public void testDefaultLogLevel() {
   builder.build();
   assertThat(builder.getLogLevel()).isEqualTo(LogLevel.NONE);
 }
Beispiel #14
0
 @Test
 public void testHighestEncryptionMethodWithPasword() {
   builder.setEncryptionMethod(HawkBuilder.EncryptionMethod.HIGHEST).setPassword("test");
   assertThat(builder.getEncryptionMethod()).isEqualTo(HawkBuilder.EncryptionMethod.HIGHEST);
 }