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

Adding availableKeys to ParseObject.State #596

Merged
merged 10 commits into from
Mar 13, 2017
6 changes: 4 additions & 2 deletions Parse/src/main/java/com/parse/ParseObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ public T apply(State other) {
for (String key : other.keySet()) {
put(key, other.get(key));
}
safeKeys(other.safeKeys());
return self();
}

Expand Down Expand Up @@ -297,15 +298,16 @@ public Set<String> safeKeys() {
public String toString() {
return String.format(Locale.US, "%s@%s[" +
"className=%s, objectId=%s, createdAt=%d, updatedAt=%d, isComplete=%s, " +
"serverData=%s]",
"serverData=%s, safeKeys=%s]",
getClass().getName(),
Integer.toHexString(hashCode()),
className,
objectId,
createdAt,
updatedAt,
isComplete,
serverData);
serverData,
safeKeys);
}
}

Expand Down
7 changes: 7 additions & 0 deletions Parse/src/test/java/com/parse/ParseObjectStateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.junit.Test;

import java.util.Arrays;
import java.util.Date;

import static org.junit.Assert.assertEquals;
Expand All @@ -30,6 +31,7 @@ public void testDefaults() {
assertEquals(-1, state.updatedAt());
assertFalse(state.isComplete());
assertTrue(state.keySet().isEmpty());
assertTrue(state.safeKeys().isEmpty());
}

@Test
Expand Down Expand Up @@ -62,6 +64,7 @@ public void testCopy() {
.isComplete(true)
.put("foo", "bar")
.put("baz", "qux")
.safeKeys(Arrays.asList("safe", "keys"))
.build();
ParseObject.State copy = new ParseObject.State.Builder(state).build();
assertEquals(state.className(), copy.className());
Expand All @@ -72,6 +75,9 @@ public void testCopy() {
assertEquals(state.keySet().size(), copy.keySet().size());
assertEquals(state.get("foo"), copy.get("foo"));
assertEquals(state.get("baz"), copy.get("baz"));
assertEquals(state.safeKeys().size(), copy.safeKeys().size());
assertTrue(state.safeKeys().containsAll(copy.safeKeys()));
assertTrue(copy.safeKeys().containsAll(state.safeKeys()));
}

@Test
Expand Down Expand Up @@ -121,5 +127,6 @@ public void testToString() {
assertTrue(string.contains("updatedAt"));
assertTrue(string.contains("isComplete"));
assertTrue(string.contains("serverData"));
assertTrue(string.contains("safeKeys"));
}
}
10 changes: 10 additions & 0 deletions Parse/src/test/java/com/parse/ParseObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -237,7 +238,16 @@ public void testGetUnavailable() {
ParseObject.State state = mock(ParseObject.State.class);
when(state.className()).thenReturn("TestObject");
when(state.isComplete()).thenReturn(false);
ParseObject object = ParseObject.from(state);
object.get("foo");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just an assertion that no exception will be raised?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this checks that the exception is raised (see the @test annotation). Actually I have not changed this method, I have added testGetAvailableIfKeySafe() a few lines below, that tests safeKeys() .

}

@Test
public void testGetAvailableIfKeySafe() {
ParseObject.State state = mock(ParseObject.State.class);
when(state.className()).thenReturn("TestObject");
when(state.isComplete()).thenReturn(false);
when(state.safeKeys()).thenReturn(new HashSet<>(Arrays.asList("foo")));
ParseObject object = ParseObject.from(state);
object.get("foo");
}
Expand Down