From 09ba4bbe4d8ccad08d634be676eb58576ea18b95 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sat, 9 Sep 2006 15:44:03 +0000 Subject: Added more OrderingList tests. --- .../com/amazon/carbonado/qe/TestOrderingList.java | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'src/test/java/com') diff --git a/src/test/java/com/amazon/carbonado/qe/TestOrderingList.java b/src/test/java/com/amazon/carbonado/qe/TestOrderingList.java index b696984..ea9bc10 100644 --- a/src/test/java/com/amazon/carbonado/qe/TestOrderingList.java +++ b/src/test/java/com/amazon/carbonado/qe/TestOrderingList.java @@ -107,4 +107,104 @@ public class TestOrderingList extends TestCase { } catch (IllegalArgumentException e) { } } + + public void testImmutable() throws Exception { + List> list = + OrderingList.get(StorableTestBasic.class, "~date"); + try { + list.set(0, list.get(0).reverse()); + fail(); + } catch (UnsupportedOperationException e) { + } + } + + public void testConcatList() throws Exception { + OrderingList list_1 = + OrderingList.get(StorableTestBasic.class, "date", "-intProp", "~stringProp"); + + OrderingList list_2 = + OrderingList.get(StorableTestBasic.class, "longProp", "doubleProp"); + + OrderingList list_3 = list_1.concat(list_2); + + assertEquals(5, list_3.size()); + assertEquals("+date", list_3.get(0).toString()); + assertEquals("-intProp", list_3.get(1).toString()); + assertEquals("~stringProp", list_3.get(2).toString()); + assertEquals("+longProp", list_3.get(3).toString()); + assertEquals("+doubleProp", list_3.get(4).toString()); + + OrderingList list_4 = + OrderingList.get(StorableTestBasic.class, + "+date", "-intProp", "~stringProp", "longProp", "+doubleProp"); + + assertEquals(list_3, list_4); + assertTrue(list_3 == list_4); + } + + public void testReverseDirections() throws Exception { + OrderingList list_1 = + OrderingList.get(StorableTestBasic.class, "date", "-intProp", "~stringProp"); + + list_1 = list_1.reverseDirections(); + + assertEquals(3, list_1.size()); + assertEquals("-date", list_1.get(0).toString()); + assertEquals("+intProp", list_1.get(1).toString()); + assertEquals("~stringProp", list_1.get(2).toString()); + + OrderingList list_2 = + OrderingList.get(StorableTestBasic.class, "-date", "intProp", "~stringProp"); + + assertEquals(list_1, list_2); + assertTrue(list_1 == list_2); + } + + public void testReplace() throws Exception { + OrderingList list_1 = + OrderingList.get(StorableTestBasic.class, "date", "-intProp", "~stringProp"); + + OrderedProperty op_0 = list_1.get(0); + OrderedProperty op_1 = list_1.get(1); + OrderedProperty op_2 = list_1.get(2); + + list_1 = list_1.replace(0, op_1); + list_1 = list_1.replace(1, op_2); + list_1 = list_1.replace(2, op_0); + + assertEquals(3, list_1.size()); + assertEquals("-intProp", list_1.get(0).toString()); + assertEquals("~stringProp", list_1.get(1).toString()); + assertEquals("+date", list_1.get(2).toString()); + + OrderingList list_2 = + OrderingList.get(StorableTestBasic.class, "-intProp", "~stringProp", "+date"); + + assertEquals(list_1, list_2); + assertTrue(list_1 == list_2); + } + + public void testAsArray() throws Exception { + OrderingList list = + OrderingList.get(StorableTestBasic.class, "date", "intProp", "stringProp"); + + OrderedProperty[] array = list.asArray(); + + assertEquals(3, array.length); + assertEquals("+date", array[0].toString()); + assertEquals("+intProp", array[1].toString()); + assertEquals("+stringProp", array[2].toString()); + } + + public void testAsStringArray() throws Exception { + OrderingList list = + OrderingList.get(StorableTestBasic.class, "date", "intProp", "stringProp"); + + String[] array = list.asStringArray(); + + assertEquals(3, array.length); + assertEquals("+date", array[0]); + assertEquals("+intProp", array[1]); + assertEquals("+stringProp", array[2]); + } } -- cgit v1.2.3