Search in sources :

Example 1 with TestDatabaseObject

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

the class DatabaseObjectTest method testSetAndGetDoubleValue.

public void testSetAndGetDoubleValue() {
    DatabaseObject object = null;
    object = new DatabaseObject(mContext);
    assertNotNull(object);
    assertEquals(true, object.isEmpty());
    object = new TestDatabaseObject(mContext);
    assertNotNull(object);
    object.setValue((Column) null, 1.1);
    assertEquals(true, object.isEmpty());
    object.setValue(new DoubleColumn("col_error"), 3.3);
    assertEquals(true, object.isEmpty());
    object.setValue(TestDatabaseObject.COLUMN_DOUBLE_VAL, 1.414);
    assertEquals(1.414, object.getDoubleValue(TestDatabaseObject.COLUMN_DOUBLE_VAL));
    object.setValue(TestDatabaseObject.COLUMN_DOUBLE_VAL.getName(), 1.732);
    assertEquals(1.732, object.getDoubleValue(TestDatabaseObject.COLUMN_DOUBLE_VAL.getName()));
    assertEquals(.0, object.getDoubleValue(TestDatabaseObject.COLUMN_INTEGER_VAL));
    assertEquals(.0, object.getDoubleValue(TestDatabaseObject.COLUMN_LONG_VAL));
    assertEquals(.0, object.getDoubleValue(TestDatabaseObject.COLUMN_TEXT_VAL));
    assertEquals(.0, object.getDoubleValue(TestDatabaseObject.COLUMN_BLOB_VAL));
    assertEquals(.0, object.getDoubleValue(new DoubleColumn("dummy")));
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject)

Example 2 with TestDatabaseObject

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

the class DatabaseObjectTest method testListNonEmptyColumns.

public void testListNonEmptyColumns() {
    DatabaseObject object = new TestDatabaseObject(mContext);
    assertNotNull(object);
    object.setValue(TestDatabaseObject.COLUMN_INTEGER_VAL, 888);
    object.setValue(TestDatabaseObject.COLUMN_LONG_VAL, 123456789l);
    List<Column> expected = new ArrayList<Column>();
    assertNotNull(expected);
    expected.add(TestDatabaseObject.COLUMN_INTEGER_VAL);
    expected.add(TestDatabaseObject.COLUMN_LONG_VAL);
    Asserts.assertEquals(expected, object.listNonEmptyColumns());
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) ArrayList(java.util.ArrayList) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject)

Example 3 with TestDatabaseObject

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

the class DatabaseObjectTest method testSetAndGetLongValue.

public void testSetAndGetLongValue() {
    DatabaseObject object = null;
    object = new DatabaseObject(mContext);
    assertNotNull(object);
    assertEquals(true, object.isEmpty());
    object = new TestDatabaseObject(mContext);
    assertNotNull(object);
    object.setValue((Column) null, 1l);
    assertEquals(true, object.isEmpty());
    object.setValue(new LongColumn("col_error"), 3l);
    assertEquals(true, object.isEmpty());
    object.setValue(TestDatabaseObject.COLUMN_LONG_VAL, 123456789l);
    assertEquals(123456789l, object.getLongValue(TestDatabaseObject.COLUMN_LONG_VAL));
    object.setValue(TestDatabaseObject.COLUMN_LONG_VAL.getName(), 123454321l);
    assertEquals(123454321l, object.getLongValue(TestDatabaseObject.COLUMN_LONG_VAL.getName()));
    assertEquals(0l, object.getLongValue(TestDatabaseObject.COLUMN_INTEGER_VAL));
    assertEquals(0l, object.getLongValue(TestDatabaseObject.COLUMN_DOUBLE_VAL));
    assertEquals(0l, object.getLongValue(TestDatabaseObject.COLUMN_TEXT_VAL));
    assertEquals(0l, object.getLongValue(TestDatabaseObject.COLUMN_BLOB_VAL));
    assertEquals(0l, object.getLongValue(new LongColumn("dummy")));
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject)

Example 4 with TestDatabaseObject

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

the class DatabaseObjectTest method testSetAndGetBlobValue.

public void testSetAndGetBlobValue() {
    DatabaseObject object = null;
    final byte[] BINARY_A = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
    final byte[] BINARY_B = { (byte) 0xFF, (byte) 0xFE, (byte) 0xFD, (byte) 0xFC, (byte) 0xFB, (byte) 0xFA, (byte) 0xF9, (byte) 0xF8, (byte) 0xF7, (byte) 0xF6, (byte) 0xF5, (byte) 0xF4, (byte) 0xF3, (byte) 0xF2, (byte) 0xF1, (byte) 0xF0 };
    final byte[] BINARY_C = {};
    object = new DatabaseObject(mContext);
    assertNotNull(object);
    assertEquals(true, object.isEmpty());
    object = new TestDatabaseObject(mContext);
    assertNotNull(object);
    object.setValue((Column) null, BINARY_A);
    assertEquals(true, object.isEmpty());
    object.setValue(new TextColumn("col_error"), BINARY_A);
    assertEquals(true, object.isEmpty());
    object.setValue(TestDatabaseObject.COLUMN_BLOB_VAL, BINARY_A);
    Asserts.assertEquals(BINARY_A, object.getBlobValue(TestDatabaseObject.COLUMN_BLOB_VAL));
    object.setValue(TestDatabaseObject.COLUMN_BLOB_VAL, BINARY_C);
    Asserts.assertEquals(BINARY_C, object.getBlobValue(TestDatabaseObject.COLUMN_BLOB_VAL));
    object.setValue(TestDatabaseObject.COLUMN_BLOB_VAL, BINARY_B);
    Asserts.assertEquals(BINARY_B, object.getBlobValue(TestDatabaseObject.COLUMN_BLOB_VAL));
    assertNull(object.getBlobValue(TestDatabaseObject.COLUMN_INTEGER_VAL));
    assertNull(object.getBlobValue(TestDatabaseObject.COLUMN_LONG_VAL));
    assertNull(object.getBlobValue(TestDatabaseObject.COLUMN_DOUBLE_VAL));
    assertNull(object.getBlobValue(TestDatabaseObject.COLUMN_TEXT_VAL));
    assertNull(object.getBlobValue(new BlobColumn("dummy")));
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject)

Example 5 with TestDatabaseObject

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

the class DatabaseObjectTest method testToSQLSelectionString.

public void testToSQLSelectionString() {
    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");
    assertEquals("intVal = 888 AND longVal = 123456789 AND doubleVal = 3.1415926 AND textVal = \'This is a text value\'", object.toSQLSelectionString());
}
Also used : TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject) TestDatabaseObject(com.dailystudio.dataobject.samples.TestDatabaseObject)

Aggregations

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