io.realm.log.RealmLog Java Examples

The following examples show how to use io.realm.log.RealmLog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDataModule.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Init realm configuration and instance
 * @return
 * @throws Exception
 */
@Provides
@Singleton
RealmConfiguration provideRealmConfiguration(){
    mockStatic(RealmCore.class);
    mockStatic(RealmLog.class);
    mockStatic(Realm.class);
    mockStatic(RealmConfiguration.class);
    Realm.init(RuntimeEnvironment.application);

    // TODO: Better solution would be just mock the RealmConfiguration.Builder class. But it seems there is some
    // problems for powermock to mock it (static inner class). We just mock the RealmCore.loadLibrary(Context) which
    // will be called by RealmConfiguration.Builder's constructor.
    doNothing().when(RealmCore.class);
    RealmCore.loadLibrary(any(Context.class));

    final RealmConfiguration mockRealmConfig = PowerMockito.mock(RealmConfiguration.class);

    try {
        whenNew(RealmConfiguration.class).withAnyArguments().thenReturn(mockRealmConfig);
    } catch (Exception e) {
        e.printStackTrace();
    }

    when(Realm.getDefaultConfiguration()).thenReturn(mockRealmConfig);

    // init mock realm
    Realm mockRealm = PowerMockito.mock(Realm.class);;
    // Anytime getInstance is called with any configuration, then return the mockRealm
    when(Realm.getDefaultInstance()).thenReturn(mockRealm);

    when(Realm.getInstance(mockRealmConfig)).thenReturn(mockRealm);

    return mockRealmConfig;
}
 
Example #2
Source File: SimpleRealmTest.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@Before
public void setup() {
    mockStatic(RealmLog.class);
    mockStatic(Realm.class);

    Realm mockRealm = PowerMockito.mock(Realm.class);

    when(Realm.getDefaultInstance()).thenReturn(mockRealm);
    this.mockRealm = mockRealm;
}
 
Example #3
Source File: SecureUserStore.java    From realm-android-user-store with Apache License 2.0 5 votes vote down vote up
/**
 * Encrypt then save a {@link SyncUser} object. If another user already exists, it will be replaced.
 *  {@link SyncUser#getIdentity()} is used as a unique identifier of a given {@link SyncUser}.
 *
 * @param user {@link SyncUser} object to store.
 */
@Override
public void put(SyncUser user) {
    try {
        String userSerialisedAndEncrypted = cipherClient.encrypt(user.toJson());
        nativeUpdateOrCreateUser(user.getIdentity(), userSerialisedAndEncrypted, user.getAuthenticationUrl().toString());
    } catch (KeyStoreException e) {
        RealmLog.error(e);
    }
}
 
Example #4
Source File: SecureUserStore.java    From realm-android-user-store with Apache License 2.0 5 votes vote down vote up
private SyncUser toDecryptedSyncUserOrNull(String userEncryptedJson) {
    if (userEncryptedJson != null) {
        try {
            String userSerialisedAndDecrypted = cipherClient.decrypt(userEncryptedJson);
            return SyncUser.fromJson(userSerialisedAndDecrypted);
        } catch (KeyStoreException e) {
            RealmLog.error(e);
            return null;
        }
    }
    return null;
}
 
Example #5
Source File: ProjectsActivity.java    From my-first-realm-app with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_items);

    setSupportActionBar(findViewById(R.id.toolbar));

    findViewById(R.id.fab).setOnClickListener(view -> {
        View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_task, null);
        ((EditText) dialogView.findViewById(R.id.task)).setHint(R.string.project_description);
        EditText taskText = dialogView.findViewById(R.id.task);
        new AlertDialog.Builder(ProjectsActivity.this)
                .setTitle("Add a new project")
                .setView(dialogView)
                .setPositiveButton("Add", (dialog, which) -> realm.executeTransactionAsync(realm -> {
                    String userId = SyncUser.current().getIdentity();
                    String name = taskText.getText().toString();

                    Project project = new Project();
                    project.setId(UUID.randomUUID().toString());
                    project.setOwner(userId);
                    project.setName(name);
                    project.setTimestamp(new Date());

                    realm.insert(project);
                }, error -> RealmLog.error(error) ))
                .setNegativeButton("Cancel", null)
                .create()
                .show();
    });

    // Create a  subscription that only download the  users projects from the server.
    realm = Realm.getDefaultInstance();
    RealmResults<Project> projects = realm
            .where(Project.class)
            .equalTo("owner", SyncUser.current().getIdentity())
            .sort("timestamp", Sort.DESCENDING)
            .findAllAsync();

    final ProjectsRecyclerAdapter itemsRecyclerAdapter = new ProjectsRecyclerAdapter(this, projects);
    RecyclerView recyclerView = findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(itemsRecyclerAdapter);
}