Search in sources :

Example 1 with PreferencesAdapter

use of com.codeslap.persistence.PreferencesAdapter in project persistence by casidiablo.

the class PrefInsertionTest method shouldInsertAndRetrieveTheSameBean.

@Test
public void shouldInsertAndRetrieveTheSameBean() {
    PreferencesAdapter adapter = Persistence.getPreferenceAdapter(new Activity());
    // should retrieve an empty object when it is possible to create one
    assertNotNull(adapter.retrieve(PreferenceBean.class));
    PreferenceBean bean = new PreferenceBean();
    bean.veryLong = Long.MAX_VALUE;
    bean.name = "Foo Bar Baz";
    bean.bool = true;
    bean.decimal = Float.MAX_VALUE;
    bean.number = Integer.MAX_VALUE;
    adapter.store(bean);
    PreferenceBean found = adapter.retrieve(PreferenceBean.class);
    assertEquals(bean, found);
    // now let's delete everything
    assertTrue(adapter.delete(PreferenceBean.class));
    // it should now have default values
    PreferenceBean retrieve = adapter.retrieve(PreferenceBean.class);
    assertEquals(0, retrieve.number);
    assertEquals(null, retrieve.name);
    assertEquals(0f, retrieve.decimal, 0);
    assertEquals(false, retrieve.bool);
    assertEquals(0L, retrieve.veryLong);
}
Also used : Activity(android.app.Activity) PreferencesAdapter(com.codeslap.persistence.PreferencesAdapter) Test(org.junit.Test)

Example 2 with PreferencesAdapter

use of com.codeslap.persistence.PreferencesAdapter in project persistence by casidiablo.

the class PrefInsertionTest method shouldInsertAndRetrieveTheSameBeanWithAnnotations.

@Test
public void shouldInsertAndRetrieveTheSameBeanWithAnnotations() {
    PreferencesAdapter adapter = Persistence.getPreferenceAdapter(new Activity());
    // should retrieve an empty object when it is possible to create one
    assertNotNull(adapter.retrieve(PrefWithAnnotations.class));
    PrefWithAnnotations bean = new PrefWithAnnotations();
    bean.veryLong = Long.MAX_VALUE;
    bean.name = "Foo Bar Baz";
    bean.bool = true;
    bean.decimal = Float.MAX_VALUE;
    bean.number = Integer.MAX_VALUE;
    adapter.store(bean);
    PrefWithAnnotations found = adapter.retrieve(PrefWithAnnotations.class);
    assertEquals(bean, found);
    // now let's the delete the bean and when retrieving it again, it should have fell to default values
    assertTrue(adapter.delete(PrefWithAnnotations.class));
    PrefWithAnnotations retrieve = adapter.retrieve(PrefWithAnnotations.class);
    assertEquals(Integer.MIN_VALUE, retrieve.number);
    assertEquals(Float.MIN_VALUE, retrieve.decimal, 0);
    assertEquals(Long.MIN_VALUE, retrieve.veryLong, 0);
    assertEquals("foo bar", retrieve.name);
    assertTrue(retrieve.bool);
}
Also used : Activity(android.app.Activity) PreferencesAdapter(com.codeslap.persistence.PreferencesAdapter) Test(org.junit.Test)

Example 3 with PreferencesAdapter

use of com.codeslap.persistence.PreferencesAdapter in project persistence by casidiablo.

the class PrefRetrieveTest method shouldReturnFullObjectWhenUsingAnnotationsFromSpecificPreference.

@Test
public void shouldReturnFullObjectWhenUsingAnnotationsFromSpecificPreference() {
    PreferencesAdapter adapter = Persistence.getPreferenceAdapter(new Activity(), "test.pref");
    PrefWithAnnotations retrieve = adapter.retrieve(PrefWithAnnotations.class);
    assertEquals(Integer.MIN_VALUE, retrieve.number);
    assertEquals(Float.MIN_VALUE, retrieve.decimal, 0);
    assertEquals(Long.MIN_VALUE, retrieve.veryLong, 0);
    assertEquals("foo bar", retrieve.name);
    assertTrue(retrieve.bool);
}
Also used : Activity(android.app.Activity) PreferencesAdapter(com.codeslap.persistence.PreferencesAdapter) Test(org.junit.Test)

Example 4 with PreferencesAdapter

use of com.codeslap.persistence.PreferencesAdapter in project persistence by casidiablo.

the class PrefHelperTest method prefHelperTest.

@Test
public void prefHelperTest() {
    PreferencesAdapter adapter = Persistence.getPreferenceAdapter(new Activity());
    assertNotNull(adapter);
    adapter = Persistence.getPreferenceAdapter(new Activity(), "test.pref");
    assertNotNull(adapter);
}
Also used : Activity(android.app.Activity) PreferencesAdapter(com.codeslap.persistence.PreferencesAdapter) Test(org.junit.Test)

Example 5 with PreferencesAdapter

use of com.codeslap.persistence.PreferencesAdapter in project persistence by casidiablo.

the class PrefInsertionTest method shouldFailWhenBeanIsNotAssociated.

@Test(expected = IllegalStateException.class)
public void shouldFailWhenBeanIsNotAssociated() {
    PreferencesAdapter adapter = Persistence.getPreferenceAdapter(new Activity());
    adapter.store(String.class);
}
Also used : Activity(android.app.Activity) PreferencesAdapter(com.codeslap.persistence.PreferencesAdapter) Test(org.junit.Test)

Aggregations

Activity (android.app.Activity)7 PreferencesAdapter (com.codeslap.persistence.PreferencesAdapter)7 Test (org.junit.Test)7