From 9868f50714076f9dc90e7021a45324411afd9ce1 Mon Sep 17 00:00:00 2001 From: Chris Jaekl Date: Mon, 14 Dec 2015 20:32:00 +0900 Subject: [PATCH] Check edge cases in Location getters --- prod/net/jaekl/cfb/store/Location.java | 4 +- test/net/jaekl/cfb/store/LocationTest.java | 48 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 test/net/jaekl/cfb/store/LocationTest.java diff --git a/prod/net/jaekl/cfb/store/Location.java b/prod/net/jaekl/cfb/store/Location.java index 91aed9f..17d081a 100644 --- a/prod/net/jaekl/cfb/store/Location.java +++ b/prod/net/jaekl/cfb/store/Location.java @@ -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 index 0000000..a40c355 --- /dev/null +++ b/test/net/jaekl/cfb/store/LocationTest.java @@ -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())); + } + } + } + +} -- 2.30.2