@Test public void addUserTest() { when(realmMock.createObject(User.class, user.getId())).thenReturn(realmUserMock); final boolean isSuccessful = datastoreAddActions.user(user); verify(realmMock, times(1)).beginTransaction(); verify(realmMock, times(1)).createObject(User.class, user.getId()); verify(realmUserMock, times(1)).setName(user.getName()); verify(realmUserMock, times(1)).setUsername(user.getUsername()); verify(realmUserMock, times(1)).setEmail(user.getEmail()); verifyNoMoreInteractions(realmUserMock); verify(realmMock, times(1)).commitTransaction(); verifyNoMoreInteractions(realmMock); assertThat(isSuccessful).isTrue(); }
@Override public boolean user(final User user) { realm.beginTransaction(); final User newRealmUser = realm.createObject(User.class, user.getId()); newRealmUser.setName(user.getName()); newRealmUser.setUsername(user.getUsername()); newRealmUser.setEmail(user.getEmail()); realm.commitTransaction(); return true; }
DatastoreAddActions implements AddActions { @Override public boolean user(final User user) { realm.beginTransaction(); final User newRealmUser = realm.createObject(User.class, user.getId()); newRealmUser.setName(user.getName()); newRealmUser.setUsername(user.getUsername()); newRealmUser.setEmail(user.getEmail()); realm.commitTransaction(); return true; } }
DatastoreAddActions implements AddActions { @Override public boolean user(final User user) { realm.beginTransaction(); final User newRealmUser = realm.createObject(User.class, user.getId()); newRealmUser.setName(user.getName()); newRealmUser.setUsername(user.getUsername()); newRealmUser.setEmail(user.getEmail()); realm.commitTransaction(); return true; } DatastoreAddActions(final Realm realm); }
DatastoreAddActions implements AddActions { @Override public boolean user(final User user) { realm.beginTransaction(); final User newRealmUser = realm.createObject(User.class, user.getId()); newRealmUser.setName(user.getName()); newRealmUser.setUsername(user.getUsername()); newRealmUser.setEmail(user.getEmail()); realm.commitTransaction(); return true; } DatastoreAddActions(final Realm realm); @Override boolean user(final User user); }
DatastoreAddActions implements AddActions { @Override public boolean user(final User user) { realm.beginTransaction(); final User newRealmUser = realm.createObject(User.class, user.getId()); newRealmUser.setName(user.getName()); newRealmUser.setUsername(user.getUsername()); newRealmUser.setEmail(user.getEmail()); realm.commitTransaction(); return true; } DatastoreAddActions(final Realm realm); @Override boolean user(final User user);  }