Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing squid: S1192 String literals should not be duplicated #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions library/src/androidTest/java/com/cocosw/favor/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
*/
public class ApplicationTest extends ApplicationTestCase<Application> {

private static final String SYDNEY = "Sydney";
private static final String PASSWORD = "Password";
private static final String EXTRA = "extra";
private static final String ALIVE = "alive";
private static final String UNSUPPORTED_TYPE = "Unsupported type";
private static final String UNSUPPORTED_TYPE_FAILURE = "Fail to check unsupported value type";

private Profile profile;

public ApplicationTest() {
Expand All @@ -34,8 +41,8 @@ protected void setUp() throws Exception {
}

public void testGetValue() {
setSP("city", "Sydney");
Assert.assertEquals("Sydney", profile.city());
setSP("city", SYDNEY);
Assert.assertEquals(SYDNEY, profile.city());
}

public void testPutValue() {
Expand All @@ -47,8 +54,8 @@ public void testPutValue() {

public void testDefaultValue() {
remove("city");
Assert.assertEquals("Sydney", profile.city());
remove("alive");
Assert.assertEquals(SYDNEY, profile.city());
remove(ALIVE);
Assert.assertEquals(true, profile.alive());
remove("height");
Assert.assertEquals(170, profile.getHeight());
Expand All @@ -65,11 +72,11 @@ public void testLongValue() {
}

public void testBoolValue() {
remove("alive");
remove(ALIVE);
Assert.assertEquals(true, profile.alive());
profile.isAlive(false);
Assert.assertEquals(false, profile.alive());
Assert.assertEquals(false, sp().getBoolean("alive", true));
Assert.assertEquals(false, sp().getBoolean(ALIVE, true));
}

public void testFloatValue() {
Expand All @@ -82,33 +89,33 @@ public void testAllFavor() {
FavorAdapter adapter = new FavorAdapter.Builder(getContext()).build();
adapter.enableLog(true);
Account account = adapter.create(Account.class);
remove("password");
remove(PASSWORD);
remove("username");
assertEquals("No Name", account.getUserName());
Assert.assertNull(account.getPassword());
account.setPassword("Password");
assertEquals("Password", account.getPassword());
remove("extra");
assertEquals(null, sp().getString("extra", null));
account.setExtraPassword("extra");
assertEquals("extra", sp().getString("extra", null));
account.setPassword(PASSWORD);
assertEquals(PASSWORD, account.getPassword());
remove(EXTRA);
assertEquals(null, sp().getString(EXTRA, null));
account.setExtraPassword(EXTRA);
assertEquals(EXTRA, sp().getString(EXTRA, null));
assertNull(sp().getString("extrapassword", null));
}

public void testPrefix() {
Account account = new FavorAdapter.Builder(getContext()).build().create(Account.class);
remove("password");
remove(PASSWORD);
assertNull(account.getPassword());
account.setPassword("Password");
assertEquals("Password", account.getPassword());
account.setPassword(PASSWORD);
assertEquals(PASSWORD, account.getPassword());

remove("_password");
FavorAdapter favor = new FavorAdapter.Builder(getContext()).prefix("_").build();
Account account1 = favor.create(Account.class);
assertNull(account1.getPassword());
account1.setPassword("Password");
assertEquals("Password", account1.getPassword());
assertEquals("Password", sp().getString("_password", null));
account1.setPassword(PASSWORD);
assertEquals(PASSWORD, account1.getPassword());
assertEquals(PASSWORD, sp().getString("_password", null));
}

public void testRxSharePreference() {
Expand Down Expand Up @@ -159,22 +166,22 @@ public void testWrongCases() {
public void run() {
wrong.testUnsupportedType(null);
}
}, "Unsupported type", "Fail to check unsupported value type");
}, UNSUPPORTED_TYPE, UNSUPPORTED_TYPE_FAILURE);

assertException(new Runnable() {
@Override
public void run() {
wrong.testUnsupportedType();
}
}, "Unsupported type", "Fail to check unsupported value type");
}, UNSUPPORTED_TYPE, UNSUPPORTED_TYPE_FAILURE);


assertException(new Runnable() {
@Override
public void run() {
wrong.testUnsupportedType(null);
}
}, "Unsupported type", "Fail to check unsupported value type");
}, UNSUPPORTED_TYPE, UNSUPPORTED_TYPE_FAILURE);

assertException(new Runnable() {
@Override
Expand Down