// This should be the place where the bug is reported.
Location getPrincipalLocation()
{
- if (null != m_locations && m_locations.size() > 0) {
- return m_locations.get(0);
+ if (null == m_locations) {
+ return null;
}
+
+ for (int idx = 0; idx < m_locations.size(); ++idx) {
+ Location loc = m_locations.get(idx);
+ if (Location.METHOD_CALLED.equals(loc.getMethodRole())) {
+ // METHOD_CALLED locations describe the method that is being called,
+ // but the bug is located in the caller, not in the callee.
+ // Thus, ignore this information about the callee.
+ continue;
+ }
+ return loc;
+ }
+
return null;
}
--- /dev/null
+package net.jaekl.cfb.xml;
+
+import static org.junit.Assert.*;
+
+import net.jaekl.cfb.store.Location;
+
+import org.junit.Test;
+
+public class BugInstanceTest {
+
+ @Test
+ public void testGetPrincpalLocation() {
+ Location[][][] data =
+ {
+ {
+ // Location(Long id, String className, String methodName, String methodRole, Integer startLine, Integer endLine)
+ {
+ // input
+ new Location( 1L, "ClassOne", "methodOne", "METHOD_CALLED", 1, 12),
+ new Location( 2L, "ClassTwo", "methodTwo", "", 23, 34)
+ },
+ {
+ // expected result
+ new Location( 2L, "ClassTwo", "methodTwo", "", 23, 34)
+ }
+ },
+ {
+ {
+ // input: empty set
+ },
+ {
+ // expected result
+ null
+ }
+ },
+ {
+ {
+ // input
+ new Location( 3L, "ClassThree", "methodThree", null, 34, 45),
+ new Location( 4L, "ClassFour", "methodFour", null, 45, 56),
+ new Location( 5L, "ClassFive", "methodFive", null, 56, 67)
+ },
+ {
+ // expected result
+ new Location( 3L, "ClassThree", "methodThree", null, 34, 45),
+ }
+ },
+ {
+ {
+ // input
+ new Location( 6L, "CLassSix", "methodSix", "METHOD_CALLED", 67, 78)
+ },
+ {
+ // expected result
+ null
+ }
+ }
+ };
+
+ for (Location[][] datum : data) {
+ Location[] input = datum[0];
+ Location expected = datum[1][0];
+
+ BugInstance bug = new BugInstance(
+ 101L, // id
+ "CATEGORY",
+ "TYPE",
+ input,
+ new LocalVariable[0]
+ );
+ Location actual = bug.getPrincipalLocation();
+
+ assertEquals(expected, actual);
+ }
+ }
+
+}