]> jaekl.net Git - cfb.git/commitdiff
Check edge cases in Location getters
authorChris Jaekl <cejaekl@yahoo.com>
Mon, 14 Dec 2015 11:32:00 +0000 (20:32 +0900)
committerChris Jaekl <cejaekl@yahoo.com>
Mon, 14 Dec 2015 11:32:00 +0000 (20:32 +0900)
prod/net/jaekl/cfb/store/Location.java
test/net/jaekl/cfb/store/LocationTest.java [new file with mode: 0644]

index 91aed9f8c32100a1a911bd74725c5ce6d5d72310..17d081a5ae1ab8f61ef4f2da6801725043e8169e 100644 (file)
@@ -57,8 +57,8 @@ public class Location {
        public String getClassName() { return m_className; }
        public String getMethodName() { return m_methodName; }
        public String getMethodRole() { return m_methodRole; }
-       public int getStart() { return m_startLine; }
-       public int getEnd() { return m_endLine; }
+       public int getStart() { return (null == m_startLine) ? (-1) : m_startLine.intValue(); }
+       public int getEnd() { return (null == m_endLine) ? (-1) : m_endLine.intValue(); }
        
        public void dump(PrintWriter pw, int indent) 
        {
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()));
+                       }
+               }
+       }
+
+}