Search in sources :

Example 6 with TestDatabaseObject

use of com.dailystudio.dataobject.samples.TestDatabaseObject in project devbricks by dailystudio.

the class DatabaseObjectTest method testConvertToIntent.

public void testConvertToIntent() {
    DatabaseObject object = new TestDatabaseObject(mContext);
    assertNotNull(object);
    object.setValue(TestDatabaseObject.COLUMN_INTEGER_VAL, 888);
    object.setValue(TestDatabaseObject.COLUMN_LONG_VAL, 123456789l);
    object.setValue(TestDatabaseObject.COLUMN_DOUBLE_VAL, 3.1415926);
    object.setValue(TestDatabaseObject.COLUMN_TEXT_VAL, "This is a text value");
    Intent actual = object.convertToIntent();
    assertNotNull(actual);
    assertEquals(888, actual.getIntExtra("intVal", 0));
    assertEquals(123456789l, actual.getLongExtra("longVal", 0l));
    assertEquals(3.1415926, actual.getDoubleExtra("doubleVal", .0));
    assertEquals("This is a text value", actual.getStringExtra("textVal"));
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) Intent(android.content.Intent)

Example 7 with TestDatabaseObject

use of com.dailystudio.dataobject.samples.TestDatabaseObject in project devbricks by dailystudio.

the class DatabaseObjectTest method testIsEmpty.

public void testIsEmpty() {
    DatabaseObject object = null;
    object = new DatabaseObject(mContext);
    assertNotNull(object);
    assertEquals(true, object.isEmpty());
    object = new TestDatabaseObject(mContext);
    assertNotNull(object);
    object.setValue(TestDatabaseObject.COLUMN_TEXT_VAL, "test");
    assertEquals(false, object.isEmpty());
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject)

Example 8 with TestDatabaseObject

use of com.dailystudio.dataobject.samples.TestDatabaseObject in project devbricks by dailystudio.

the class DatabaseObjectTest method testSetAndGetIntegerValue.

public void testSetAndGetIntegerValue() {
    DatabaseObject object = null;
    object = new DatabaseObject(mContext);
    assertNotNull(object);
    assertEquals(true, object.isEmpty());
    object = new TestDatabaseObject(mContext);
    assertNotNull(object);
    object.setValue((Column) null, 1111);
    assertEquals(true, object.isEmpty());
    object.setValue(new IntegerColumn("col_error"), 3333);
    assertEquals(true, object.isEmpty());
    object.setValue(TestDatabaseObject.COLUMN_INTEGER_VAL, 0x123456);
    assertEquals(0x123456, object.getIntegerValue(TestDatabaseObject.COLUMN_INTEGER_VAL));
    object.setValue(TestDatabaseObject.COLUMN_INTEGER_VAL.getName(), 0xfffff);
    assertEquals(0xfffff, object.getIntegerValue(TestDatabaseObject.COLUMN_INTEGER_VAL.getName()));
    assertEquals(0, object.getIntegerValue(TestDatabaseObject.COLUMN_LONG_VAL));
    assertEquals(0, object.getIntegerValue(TestDatabaseObject.COLUMN_DOUBLE_VAL));
    assertEquals(0, object.getIntegerValue(TestDatabaseObject.COLUMN_TEXT_VAL));
    assertEquals(0, object.getIntegerValue(TestDatabaseObject.COLUMN_BLOB_VAL));
    assertEquals(0, object.getIntegerValue(new IntegerColumn("dummy")));
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject)

Example 9 with TestDatabaseObject

use of com.dailystudio.dataobject.samples.TestDatabaseObject in project devbricks by dailystudio.

the class DatabaseObjectTest method testSetAndGetStringValue.

public void testSetAndGetStringValue() {
    DatabaseObject object = null;
    object = new DatabaseObject(mContext);
    assertNotNull(object);
    assertEquals(true, object.isEmpty());
    object = new TestDatabaseObject(mContext);
    assertNotNull(object);
    object.setValue((Column) null, "text1");
    assertEquals(true, object.isEmpty());
    object.setValue(new TextColumn("col_error"), "text3");
    assertEquals(true, object.isEmpty());
    object.setValue(TestDatabaseObject.COLUMN_TEXT_VAL, "test");
    assertEquals("test", object.getTextValue(TestDatabaseObject.COLUMN_TEXT_VAL));
    object.setValue(TestDatabaseObject.COLUMN_TEXT_VAL.getName(), "abcd");
    assertEquals("abcd", object.getTextValue(TestDatabaseObject.COLUMN_TEXT_VAL.getName()));
    assertNull(object.getTextValue(TestDatabaseObject.COLUMN_INTEGER_VAL));
    assertNull(object.getTextValue(TestDatabaseObject.COLUMN_LONG_VAL));
    assertNull(object.getTextValue(TestDatabaseObject.COLUMN_DOUBLE_VAL));
    assertNull(object.getTextValue(TestDatabaseObject.COLUMN_BLOB_VAL));
    assertNull(object.getTextValue(new TextColumn("dummy")));
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject)

Example 10 with TestDatabaseObject

use of com.dailystudio.dataobject.samples.TestDatabaseObject in project devbricks by dailystudio.

the class DatabaseObjectFactoryTest method testCreateDatabaseObject.

public void testCreateDatabaseObject() {
    Template templ = new Template();
    assertNotNull(templ);
    templ.addColumn(TestDatabaseObject.COLUMN_INTEGER_VAL);
    templ.addColumn(TestDatabaseObject.COLUMN_LONG_VAL);
    templ.addColumn(TestDatabaseObject.COLUMN_DOUBLE_VAL);
    templ.addColumn(TestDatabaseObject.COLUMN_TEXT_VAL);
    templ.addColumn(TestDatabaseObject.COLUMN_BLOB_VAL);
    DatabaseObject object = null;
    object = DatabaseObjectFactory.createDatabaseObject(TestDatabaseObject.class);
    assertNotNull(object);
    assertEquals(true, object instanceof TestDatabaseObject);
    assertEquals(templ, object.getTemplate());
    MockCursor cursor = new SimpleMockCursor();
    assertNotNull(cursor);
    assertEquals(true, cursor.moveToFirst());
    int i = 0;
    do {
        object = DatabaseObjectFactory.createDatabaseObject(TestDatabaseObject.class);
        assertNotNull(object);
        object.fillValuesFromCursor(cursor);
        assertEquals(true, object instanceof TestDatabaseObject);
        assertEquals(templ, object.getTemplate());
        assertEquals(i, object.getIntegerValue(TestDatabaseObject.COLUMN_INTEGER_VAL));
        assertEquals(i * 1000l, object.getLongValue(TestDatabaseObject.COLUMN_LONG_VAL));
        assertEquals(i * 0.0001, object.getDoubleValue(TestDatabaseObject.COLUMN_DOUBLE_VAL));
        assertEquals(String.format("Text%03d", i), object.getTextValue(TestDatabaseObject.COLUMN_TEXT_VAL));
        i++;
    } while (cursor.moveToNext());
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) MockCursor(android.test.mock.MockCursor)

Aggregations

TestDatabaseObject (com.dailystudio.dataobject.samples.TestDatabaseObject)11 Intent (android.content.Intent)1 MockCursor (android.test.mock.MockCursor)1 ArrayList (java.util.ArrayList)1