Search in sources :

Example 1 with SimpleModel

use of com.orm.model.SimpleModel in project sugar by satyan.

the class CursorTests method testColumnNames.

@Test
public void testColumnNames() {
    save(new SimpleModel());
    Cursor c = Select.from(SimpleModel.class).getCursor();
    for (String col : new String[] { "STR", "INTEGER", "BOOL", "ID" }) {
        assertNotSame("Missing column for field: " + col, -1, c.getColumnIndex(col));
    }
}
Also used : SimpleModel(com.orm.model.SimpleModel) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 2 with SimpleModel

use of com.orm.model.SimpleModel in project sugar by satyan.

the class CursorTests method testMakeAdapter.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testMakeAdapter() {
    save(new SimpleModel());
    Cursor c = Select.from(SimpleModel.class).getCursor();
    CursorAdapter adapter = new CursorAdapter(RuntimeEnvironment.application, c, true) {

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            TextView tv = new TextView(context);
            String s = cursor.getString(cursor.getColumnIndex("STR"));
            tv.setText(s);
            return null;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            String s = cursor.getString(cursor.getColumnIndex("STR"));
            ((TextView) view).setText(s);
        }
    };
    Assert.assertNotNull(adapter);
}
Also used : SimpleModel(com.orm.model.SimpleModel) Context(android.content.Context) CursorAdapter(android.widget.CursorAdapter) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Cursor(android.database.Cursor) TextView(android.widget.TextView) View(android.view.View) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 3 with SimpleModel

use of com.orm.model.SimpleModel in project sugar by satyan.

the class CursorTests method testNoColumn.

@Test
public void testNoColumn() {
    save(new SimpleModel());
    Cursor cursor = Select.from(SimpleModel.class).getCursor();
    assertSame(-1, cursor.getColumnIndex("nonexistent"));
}
Also used : SimpleModel(com.orm.model.SimpleModel) Cursor(android.database.Cursor) Test(org.junit.Test)

Example 4 with SimpleModel

use of com.orm.model.SimpleModel in project sugar by satyan.

the class CursorTests method testSugarCursor.

@Test
public void testSugarCursor() {
    save(new SimpleModel());
    Cursor cursor = Select.from(SimpleModel.class).getCursor();
    assertNotSame("No _id", -1, cursor.getColumnIndex("_id"));
    assertSame("_id != ID", cursor.getColumnIndex("_id"), cursor.getColumnIndex("ID"));
}
Also used : SimpleModel(com.orm.model.SimpleModel) Cursor(android.database.Cursor) Test(org.junit.Test)

Aggregations

Cursor (android.database.Cursor)4 SimpleModel (com.orm.model.SimpleModel)4 Test (org.junit.Test)4 TargetApi (android.annotation.TargetApi)1 Context (android.content.Context)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 CursorAdapter (android.widget.CursorAdapter)1 TextView (android.widget.TextView)1