Updated tests.

This commit is contained in:
Ray Greenwell
2010-07-05 22:34:15 +00:00
parent eef66bcaee
commit 48279471e1
3 changed files with 35 additions and 5 deletions
@@ -46,6 +46,7 @@ public class AllTypesRecord extends PersistentRecord
public static final ColumnExp LONG_VALUE = colexp(_R, "longValue");
public static final ColumnExp FLOAT_VALUE = colexp(_R, "floatValue");
public static final ColumnExp DOUBLE_VALUE = colexp(_R, "doubleValue");
public static final ColumnExp BOXED_BOOLEAN = colexp(_R, "boxedBoolean");
public static final ColumnExp BOXED_BYTE = colexp(_R, "boxedByte");
public static final ColumnExp BOXED_SHORT = colexp(_R, "boxedShort");
public static final ColumnExp BOXED_INT = colexp(_R, "boxedInt");
@@ -58,6 +59,7 @@ public class AllTypesRecord extends PersistentRecord
public static final ColumnExp DATE = colexp(_R, "date");
public static final ColumnExp TIME = colexp(_R, "time");
public static final ColumnExp TIMESTAMP = colexp(_R, "timestamp");
public static final ColumnExp NULL_BOXED_BOOLEAN = colexp(_R, "nullBoxedBoolean");
public static final ColumnExp NULL_BOXED_BYTE = colexp(_R, "nullBoxedByte");
public static final ColumnExp NULL_BOXED_SHORT = colexp(_R, "nullBoxedShort");
public static final ColumnExp NULL_BOXED_INT = colexp(_R, "nullBoxedInt");
@@ -22,10 +22,15 @@ package com.samskivert.depot.tests;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.samskivert.depot.Key;
import com.samskivert.depot.expression.ColumnExp;
@@ -34,6 +39,7 @@ import com.samskivert.depot.PersistenceContext;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.Transformer;
import com.samskivert.depot.Transformers;
import com.samskivert.depot.annotation.Column;
import com.samskivert.depot.annotation.Id;
import com.samskivert.depot.annotation.Transform;
import com.samskivert.depot.impl.FieldMarshaller;
@@ -119,6 +125,8 @@ public class TransformTest extends TestBase
public static final Class<TransformRecord> _R = TransformRecord.class;
public static final ColumnExp RECORD_ID = colexp(_R, "recordId");
public static final ColumnExp STRINGS = colexp(_R, "strings");
public static final ColumnExp STRING_LIST = colexp(_R, "stringList");
public static final ColumnExp STRING_SET = colexp(_R, "stringSet");
public static final ColumnExp CUSTOM = colexp(_R, "custom");
public static final ColumnExp ORDINAL = colexp(_R, "ordinal");
// AUTO-GENERATED: FIELDS END
@@ -127,9 +135,15 @@ public class TransformTest extends TestBase
@Id public int recordId;
@Transform(Transformers.TabSeparatedString.class)
@Column(nullable=true) @Transform(Transformers.StringArray.class)
public String[] strings;
@Column(nullable=true) @Transform(Transformers.StringIterable.class)
public List<String> stringList;
@Column(nullable=true) @Transform(Transformers.StringIterable.class)
public Set<String> stringSet;
public CustomType custom;
public Ordinal ordinal;
@@ -193,10 +207,22 @@ public class TransformTest extends TestBase
}
@Test public void testCreateReadDelete ()
{
testCreateReadDelete(new String[] { "one", "two", "three" });
testCreateReadDelete(new String[] { ",", null, "" });
testCreateReadDelete(new String[] { "" });
testCreateReadDelete(new String[] {});
testCreateReadDelete(null);
testCreateReadDelete(new String[] { "", "\n", "", "\n\n" });
}
protected void testCreateReadDelete (String[] strings)
{
TransformRecord in = new TransformRecord();
in.recordId = 1;
in.strings = new String[] { "one", "two", "three" };
in.strings = strings;
in.stringList = (strings == null) ? null : Lists.newArrayList(strings);
in.stringSet = (strings == null) ? null : Sets.newHashSet(strings);
in.custom = new CustomType("custom");
in.ordinal = Ordinal.THREE;
_repo.insert(in);
@@ -208,6 +234,8 @@ public class TransformTest extends TestBase
// make sure all of the fields were marshalled and unmarshalled correctly
assertEquals(in.recordId, out.recordId);
assertArrayEquals(in.strings, out.strings);
assertTrue(Objects.equal(in.stringList, out.stringList));
assertTrue(Objects.equal(in.stringSet, out.stringSet));
assertEquals(in.custom, out.custom);
assertEquals(in.ordinal, out.ordinal);
@@ -37,15 +37,15 @@ public class TransformersTest
@Test public void testTabSeparatedString ()
{
String[] data = { "notabs", "\tpretab", "posttab\t", "in\ttab", "\t\t\tOMGtabs!\t\t" };
Transformers.TabSeparatedString xform = new Transformers.TabSeparatedString();
Transformers.StringArray xform = new Transformers.StringArray();
assertArrayEquals(data, xform.fromPersistent(null, xform.toPersistent(data)));
}
@Test public void testEmpties ()
{
Transformers.TabSeparatedString xform = new Transformers.TabSeparatedString();
Transformers.StringArray xform = new Transformers.StringArray();
Set<String> set = Sets.newHashSet();
// set.add(xform.toPersistent(null));
set.add(xform.toPersistent(null));
set.add(xform.toPersistent(new String[] {}));
set.add(xform.toPersistent(new String[] {""}));
assertTrue(set.size() == 3);