Skip to content

Commit

Permalink
Add test for default column names.
Browse files Browse the repository at this point in the history
As per @harward's excellent commit:

f803f1a
  • Loading branch information
joshuapinter committed Apr 6, 2014
1 parent 87bb981 commit 72d4a4c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/src/com/activeandroid/test/MockModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,22 @@
*/

import com.activeandroid.Model;
import com.activeandroid.annotation.Column;
import com.activeandroid.annotation.Table;

import java.util.Date;

@Table(name = "MockModel")
public class MockModel extends Model {
@Column
public Date dateField;

@Column
public double doubleField;

@Column
public int intField;

@Column
public boolean booleanField;
}
17 changes: 17 additions & 0 deletions tests/src/com/activeandroid/test/ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

package com.activeandroid.test;

import com.activeandroid.Cache;
import com.activeandroid.Model;
import com.activeandroid.TableInfo;
import com.activeandroid.annotation.Table;

import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -125,6 +128,20 @@ public void testHashCodeDifferentRows() {
assertEquals(2, set.size());
}

/**
* Column names should default to the field name.
*/
public void testColumnNamesDefaulToFieldNames() {
TableInfo tableInfo = Cache.getTableInfo(MockModel.class);

for ( Field field : tableInfo.getFields() ) {
// Id column is a special case, we'll ignore that one.
if ( field.getName().equals("mId") ) continue;

assertEquals(field.getName(), tableInfo.getColumnName(field));
}
}

/**
* Mock model as we need 2 different model classes.
*/
Expand Down

0 comments on commit 72d4a4c

Please sign in to comment.