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

feat: MLIBZ-2447 Extending user class with properties of different class cause an exception #167

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.kinvey.androidTest.model;

import com.google.api.client.json.GenericJson;
import com.google.api.client.util.Key;

public class InternalUserEntity extends GenericJson {

@Key
private String street;

public String getStreet() {
return street;
}

public void setStreet(String street) {
this.street = street;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ public class TestUser extends User {
@Key("companyName")
private String companyName;

public TestUser() {

}
@Key
private InternalUserEntity internalUserEntity;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have a test case where the User class is extended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


public String getCompanyName() {
return companyName;
Expand All @@ -19,4 +18,12 @@ public String getCompanyName() {
public void setCompanyName(String companyName) {
this.companyName = companyName;
}

public InternalUserEntity getInternalUserEntity() {
return internalUserEntity;
}

public void setInternalUserEntity(InternalUserEntity internalUserEntity) {
this.internalUserEntity = internalUserEntity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.kinvey.android.store.DataStore;
import com.kinvey.android.store.UserStore;
import com.kinvey.androidTest.LooperThread;
import com.kinvey.androidTest.model.InternalUserEntity;
import com.kinvey.androidTest.model.Person;
import com.kinvey.androidTest.model.TestUser;
import com.kinvey.java.Query;
Expand Down Expand Up @@ -378,11 +379,17 @@ public void testCustomSignUp() throws InterruptedException {
client.setUserClass(TestUser.class);
TestUser user = new TestUser();
user.setCompanyName("Test Company");
InternalUserEntity internalUserEntity = new InternalUserEntity();
internalUserEntity.setStreet("TestStreet");
user.setInternalUserEntity(internalUserEntity);
CustomKinveyClientCallback callback = signUp(user);
assertNull(callback.error);
assertNotNull(callback.result);
destroyUser();
assertEquals(user.getCompanyName(), callback.result.getCompanyName());
assertEquals("TestStreet", callback.result.getInternalUserEntity().getStreet());
assertEquals("Test Company", ((TestUser)client.getActiveUser()).getCompanyName());
assertEquals("TestStreet", ((TestUser)client.getActiveUser()).getInternalUserEntity().getStreet());
destroyUser();
}

@Test
Expand Down Expand Up @@ -1125,16 +1132,21 @@ public void testUpdateCustomUser() throws InterruptedException {
client.setUserClass(TestUser.class);
TestUser user = new TestUser();
user.setCompanyName("Test Company");
InternalUserEntity internalUserEntity = new InternalUserEntity();
internalUserEntity.setStreet("TestStreet");
user.setInternalUserEntity(internalUserEntity);
CustomKinveyClientCallback callback = signUp(user);
assertNull(callback.error);
assertNotNull(callback.result);

assertEquals(user.getCompanyName(), callback.result.getCompanyName(), client.getActiveUser().get("companyName"));

client.getActiveUser().set("companyName", "New Company");
((TestUser) client.getActiveUser()).getInternalUserEntity().setStreet("TestStreet2");
CustomKinveyClientCallback userKinveyClientCallback = updateCustomUser(client);
assertNotNull(userKinveyClientCallback.result);
assertNotEquals(user.getCompanyName(), userKinveyClientCallback.result.getCompanyName());
assertEquals("New Company", userKinveyClientCallback.result.getCompanyName());
assertEquals("TestStreet2", userKinveyClientCallback.result.getInternalUserEntity().getStreet());
assertNotNull(deleteUser(true, client));
}

Expand Down
18 changes: 9 additions & 9 deletions android-lib/src/main/java/com/kinvey/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public Context getContext(){
* <p/>
* This Builder class is not thread-safe.
*/
public static class Builder extends AbstractClient.Builder {
public static class Builder<T extends User> extends AbstractClient.Builder {
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be a breaking change to the client builder?

Copy link
Contributor Author

@yuliya-guseva yuliya-guseva May 31, 2018

Choose a reason for hiding this comment

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

No, It won't be breaking change.


private Context context = null;
private KinveyUserCallback<User> retrieveUserCallback = null;
Expand All @@ -447,7 +447,7 @@ public static class Builder extends AbstractClient.Builder {
private String MICVersion;
private String MICBaseURL;
private boolean deltaSetCache = false;
private Class userClass = User.class;
private Class userClass = null;
private byte[] encryptionKey;

/**
Expand Down Expand Up @@ -764,7 +764,7 @@ public Builder(Context context) {
this(context, newCompatibleTransport());
}

public Builder setUserClass(Class userClass){
public Builder setUserClass(Class<T> userClass){
this.userClass = userClass;
return this;
}
Expand Down Expand Up @@ -795,18 +795,18 @@ public Builder setInstanceID(String instanceID) {
* which contains factory methods for accessing various functionality.
*/
@Override
public Client build(){
public Client<T> build(){
kinveyHandlerThread = new KinveyHandlerThread("KinveyHandlerThread");
kinveyHandlerThread.start();
Realm.init(context);
final Client client = new Client(getTransport(),
final Client<T> client = new Client<>(getTransport(),
getHttpRequestInitializer(), getBaseUrl(),
getServicePath(), this.getObjectParser(), getKinveyClientRequestInitializer(), getCredentialStore(),
getRequestBackoffPolicy(), this.encryptionKey, this.context);

client.clientUser = AndroidUserStore.getUserStore(this.context);

client.setUserClass(userClass);
client.setUserClass(userClass != null ? userClass : User.class);

//GCM explicitly enabled
if (this.GCM_Enabled){
Expand Down Expand Up @@ -858,7 +858,7 @@ public Client build(){
*
* </p>
*
* @param buildCallback Instance of {@link: KinveyClientBuilderCallback}
* @param buildCallback Instance of {@link KinveyClientBuilderCallback}
*/
public void build(KinveyClientBuilderCallback buildCallback) {
new Build(buildCallback).execute();
Expand All @@ -868,7 +868,7 @@ public void build(KinveyClientBuilderCallback buildCallback) {
/**
* Define how credentials will be stored
*
* @param store something implpemting CredentialStore interface
* @param store something implementing CredentialStore interface
* @return this builder, with the new credential store set
*/
public Builder setCredentialStore(CredentialStore store) {
Expand All @@ -894,7 +894,7 @@ public Builder setJsonFactory(JsonFactory factory){
* Sets a callback to be called after a client is intialized and BaseUser attributes is being retrieved.
*
* <p>
* When a client is intialized after an initial login, the user's credentials are cached locally and used for the
* When a client is initialized after an initial login, the user's credentials are cached locally and used for the
* initialization of the client. As part of the initialization process, a background thread is spawned to retrieve
* up-to-date user attributes. This optional callback is called when the retrieval process is complete and passes
* an instance of the logged in user.
Expand Down
Loading