Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
carlonzo authored and Carlo Marinangeli committed Dec 9, 2015
1 parent 9903a85 commit 04f4c20
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 32 deletions.
12 changes: 4 additions & 8 deletions hawk/src/main/java/com/orhanobut/hawk/Base64Encryption.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@
* Provides Base64 Algorithm
*/
public class Base64Encryption implements Encryption {
@Override
public boolean init() {
@Override public boolean init() {
return true;
}

@Override
public String encrypt(byte[] value) {
@Override public String encrypt(byte[] value) {
return DataHelper.encodeBase64(value);
}

@Override
public byte[] decrypt(String value) {
@Override public byte[] decrypt(String value) {
return DataHelper.decodeBase64(value);
}

@Override
public boolean reset() {
@Override public boolean reset() {
return true;
}
}
6 changes: 3 additions & 3 deletions hawk/src/main/java/com/orhanobut/hawk/HawkEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private <T> T toList(String json, Class<?> type) throws Exception {
List<T> list = parser.fromJson(
json,
new TypeToken<List<T>>() {
} .getType()
}.getType()
);

int size = list.size();
Expand All @@ -124,7 +124,7 @@ private <T> T toSet(String json, Class<?> type) throws Exception {
return (T) resultSet;
}
Set<T> set = parser.fromJson(json, new TypeToken<Set<T>>() {
} .getType());
}.getType());

for (T t : set) {
String valueJson = parser.toJson(t);
Expand All @@ -141,7 +141,7 @@ private <K, V, T> T toMap(String json, Class<?> keyType, Class<?> valueType) thr
return (T) resultMap;
}
Map<K, V> map = parser.fromJson(json, new TypeToken<Map<K, V>>() {
} .getType());
}.getType());

for (Map.Entry<K, V> entry : map.entrySet()) {
String keyJson = parser.toJson(entry.getKey());
Expand Down
6 changes: 3 additions & 3 deletions hawk/src/test/java/com/orhanobut/hawk/DataHelperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.util.Base64;

import junit.framework.TestCase;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
Expand All @@ -16,11 +14,13 @@
import java.util.Map;
import java.util.Set;

import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 18)
public class DataHelperTest extends TestCase {
public class DataHelperTest {

private static final String CIPHER_TEXT = "CIPHER";

Expand Down
8 changes: 4 additions & 4 deletions hawk/src/test/java/com/orhanobut/hawk/HawkBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -21,11 +19,13 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class HawkBuilderTest extends TestCase {
public class HawkBuilderTest {

private static final long LATCH_TIMEOUT_IN_SECONDS = 5;

Expand Down Expand Up @@ -160,7 +160,7 @@ public CustomParser(Gson gson) {
builder.build();
try {
assertThat(builder.getEncryption()).isInstanceOf(AesEncryption.class);
} catch (AssertionError e){
} catch (AssertionError e) {
assertThat(builder.getEncryptionMethod()).isEqualTo(HawkBuilder.EncryptionMethod.MEDIUM);
assertThat(builder.getEncryption()).isInstanceOf(Base64Encryption.class);
}
Expand Down
5 changes: 2 additions & 3 deletions hawk/src/test/java/com/orhanobut/hawk/HawkEncoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import com.google.gson.Gson;

import junit.framework.TestCase;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
Expand All @@ -16,11 +14,12 @@
import java.util.Map;
import java.util.Set;

import static junit.framework.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 18)
public class HawkEncoderTest extends TestCase {
public class HawkEncoderTest {

private final Encoder encoder;
private final Parser parser;
Expand Down
11 changes: 6 additions & 5 deletions hawk/src/test/java/com/orhanobut/hawk/HawkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.app.Activity;
import android.content.Context;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -28,14 +26,17 @@
import rx.functions.Func1;
import rx.schedulers.Schedulers;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Orhan Obut
*/
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class HawkTest extends TestCase {
public class HawkTest {

private static final String KEY = "TAG";
private static final long LATCH_TIMEOUT_IN_SECONDS = 5;
Expand All @@ -46,15 +47,15 @@ public HawkTest() {
context = Robolectric.buildActivity(Activity.class).create().get();
}

@Override @Before public void setUp(){
@Before public void setUp() {
init();
}

public void init() {
Hawk.init(context).build();
}

@Override @After public void tearDown() {
@After public void tearDown() {
Hawk.clear();
}

Expand Down
10 changes: 4 additions & 6 deletions hawk/src/test/java/com/orhanobut/hawk/SqliteStorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import android.content.Context;
import android.util.Pair;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -17,11 +15,12 @@
import java.util.ArrayList;
import java.util.List;

import static junit.framework.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 18)
public class SqliteStorageTest extends TestCase {
public class SqliteStorageTest {

private final Context context;

Expand All @@ -31,8 +30,7 @@ public SqliteStorageTest() {
context = Robolectric.buildActivity(Activity.class).create().get();
}

@Override @Before public void setUp() throws Exception {
super.setUp();
@Before public void setUp() throws Exception {
storage = new SqliteStorage(context);
}

Expand All @@ -50,7 +48,7 @@ public SqliteStorageTest() {
}
}

@Override @After public void tearDown() {
@After public void tearDown() {
storage = null;
}

Expand Down

0 comments on commit 04f4c20

Please sign in to comment.