Check edge cases in Location getters
[cfb.git] / test / net / jaekl / cfb / store / LocationTest.java
diff --git a/test/net/jaekl/cfb/store/LocationTest.java b/test/net/jaekl/cfb/store/LocationTest.java
new file mode 100644 (file)
index 0000000..a40c355
--- /dev/null
@@ -0,0 +1,48 @@
+package net.jaekl.cfb.store;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class LocationTest {
+
+       @Test
+       public void testGetters() {
+               Object[][] data = {
+                               { Long.valueOf(1), "classname", "methodName", "methodRole", Integer.valueOf(1), Integer.valueOf(2) },
+                               { null, null, null,  null, null, null },
+                               { Long.valueOf(123456789012L), "name", "method", "role", Integer.valueOf(123456), Integer.valueOf(123456789) },
+                               { Long.valueOf(723), "", "", "", null, null },
+                               { Long.valueOf(987654321L), "class", "method", "role", Integer.valueOf(77981), Integer.valueOf(77982) },
+                               { Long.valueOf(23), "Fred", "Wilma", "Barney", Integer.valueOf(-1), null }
+               };
+               
+               for (Object[] datum : data) {
+                       Long id = (Long)datum[0];
+                       String className = (String)datum[1];
+                       String methodName = (String)datum[2];
+                       String methodRole = (String)datum[3];
+                       Integer start = (Integer)datum[4];
+                       Integer end = (Integer)datum[5];
+                       
+                       Location loc = new Location(id, className, methodName, methodRole, start, end);
+                       
+                       assertEquals(className, loc.getClassName());
+                       assertEquals(methodName, loc.getMethodName());
+                       assertEquals(methodRole, loc.getMethodRole());
+                       if (null == start) {
+                               assertEquals((-1), loc.getStart());
+                       }
+                       else {
+                               assertEquals(start, Integer.valueOf(loc.getStart()));
+                       }
+                       if (null == end) {
+                               assertEquals((-1), loc.getEnd());
+                       }
+                       else {
+                               assertEquals(end, Integer.valueOf(loc.getEnd()));
+                       }
+               }
+       }
+
+}