- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 736
Implement copying #311
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
          
     Merged
      
      
    
  
     Merged
                    Implement copying #311
Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright (c) 2015-present, Parse, LLC. | ||
| * All rights reserved. | ||
| * | ||
| * This source code is licensed under the BSD-style license found in the | ||
| * LICENSE file in the root directory of this source tree. An additional grant | ||
| * of patent rights can be found in the PATENTS file in the same directory. | ||
| */ | ||
| package com.parse; | ||
|  | ||
| import org.junit.Test; | ||
|  | ||
| import static org.junit.Assert.*; | ||
|  | ||
| public class ParseGeoPointTest { | ||
|  | ||
| @Test | ||
| public void testConstructors() { | ||
| ParseGeoPoint point = new ParseGeoPoint(); | ||
| assertEquals(0, point.getLatitude(), 0); | ||
| assertEquals(0, point.getLongitude(), 0); | ||
|  | ||
| double lat = 1.0; | ||
| double lng = 2.0; | ||
| point = new ParseGeoPoint(lat, lng); | ||
| assertEquals(lat, point.getLatitude(), 0); | ||
| assertEquals(lng, point.getLongitude(), 0); | ||
|  | ||
| ParseGeoPoint copy = new ParseGeoPoint(point); | ||
| assertEquals(lat, copy.getLatitude(), 0); | ||
| assertEquals(lng, copy.getLongitude(), 0); | ||
| } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -8,8 +8,10 @@ | |
| */ | ||
| package com.parse; | ||
|  | ||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
| import org.junit.Test; | ||
| import org.mockito.internal.util.collections.Sets; | ||
| import org.skyscreamer.jsonassert.JSONAssert; | ||
| import org.skyscreamer.jsonassert.JSONCompareMode; | ||
|  | ||
|  | @@ -20,8 +22,13 @@ | |
| import java.util.Set; | ||
|  | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertNotSame; | ||
| import static org.junit.Assert.assertSame; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.junit.Assert.fail; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|  | ||
| public class ParsePushStateTest { | ||
|  | ||
|  | @@ -56,6 +63,38 @@ public void testDefaultsWithData() throws Exception { | |
|  | ||
| //endregion | ||
|  | ||
| @Test | ||
| public void testCopy() throws JSONException { | ||
| ParsePush.State state = mock(ParsePush.State.class); | ||
| when(state.expirationTime()).thenReturn(1L); | ||
| when(state.expirationTimeInterval()).thenReturn(2L); | ||
| Set channelSet = Sets.newSet("one", "two"); | ||
| when(state.channelSet()).thenReturn(channelSet); | ||
| JSONObject data = new JSONObject(); | ||
| data.put("foo", "bar"); | ||
| when(state.data()).thenReturn(data); | ||
| when(state.pushToAndroid()).thenReturn(true); | ||
| when(state.pushToIOS()).thenReturn(false); | ||
| ParseQuery.State<ParseInstallation> queryState = | ||
| new ParseQuery.State.Builder<>(ParseInstallation.class).build(); | ||
| when(state.queryState()).thenReturn(queryState); | ||
|  | ||
| ParsePush.State copy = new ParsePush.State.Builder(state).build(); | ||
| assertSame(1L, copy.expirationTime()); | ||
| assertSame(2L, copy.expirationTimeInterval()); | ||
| Set channelSetCopy = copy.channelSet(); | ||
| assertNotSame(channelSet, channelSetCopy); | ||
| assertTrue(channelSetCopy.size() == 2 && channelSetCopy.contains("one")); | ||
| JSONObject dataCopy = copy.data(); | ||
| assertNotSame(data, dataCopy); | ||
| assertEquals("bar", dataCopy.get("foo")); | ||
| assertTrue(copy.pushToAndroid()); | ||
| assertFalse(copy.pushToIOS()); | ||
| ParseQuery.State<ParseInstallation> queryStateCopy = copy.queryState(); | ||
| assertNotSame(queryState, queryStateCopy); | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 | ||
| assertEquals("_Installation", queryStateCopy.className()); | ||
| } | ||
|  | ||
| //region testExpirationTime | ||
|  | ||
| @Test | ||
|  | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a public API, do we need to add null checking here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It implicitly NPE on the next line, which I think is fine since Java APIs work similarly: https://android.googlesource.com/platform/libcore/+/refs/heads/master/luni/src/main/java/java/util/HashMap.java#194