@Test public void testNonRootCalculator_FalsePath(){ List<MethodCall> calls = new ArrayList<>(); MethodCall call0 = new MethodCall("ClassA", "method1", 12, 1, 1); call0.branchTrace = Arrays.asList(new Integer[]{1, 2, 10}); call0.trueDistanceTrace = Arrays.asList(new Double[]{1.0, 1.0,0.5}); call0.falseDistanceTrace = Arrays.asList(new Double[]{1.0, 1.0,0.6}); calls.add(call0); ExecutionResult result = Mockito.mock(ExecutionResult.class,Mockito.RETURNS_DEEP_STUBS); Mockito.when(result.getTrace().getCoveredTrueBranches().contains(ArgumentMatchers.anyInt())).thenReturn(false); Mockito.when(result.getTrace().getMethodCalls()).thenReturn(calls); Branch branch = Mockito.mock(Branch.class,Mockito.RETURNS_DEEP_STUBS); Mockito.doReturn("ClassA").when(branch).getClassName(); Mockito.doReturn("method1").when(branch).getMethodName(); Mockito.when(branch.getInstruction().getActualCFG().getDiameter()).thenReturn(10); Mockito.when(branch.getActualBranchId()).thenReturn(10); ActualControlFlowGraph cfg = Mockito.mock(ActualControlFlowGraph.class); Mockito.doReturn("IntegrationTestingGraph").when(cfg).getClassName(); Mockito.doReturn("methodsIntegration").when(cfg).getMethodName(); Mockito.doReturn(10).when(cfg).getDiameter(); GraphPool.getInstance(BotsingTestGenerationContext.getInstance().getClassLoaderForSUT()).registerActualCFG(cfg); ControlFlowDistance cfd = InterProceduralControlFlowDistanceCalculator.getDistance(result,branch, false, "ClassA","method1"); assert(cfd.getBranchDistance() == 0.6); assert(cfd.getApproachLevel() == 0.0); }
public static ControlFlowDistance getDistance( ExecutionResult result, Branch branch, boolean value, String className, String methodName) { if (result != null && className != null && methodName != null) { if (branch == null && !value) { throw new IllegalArgumentException("expect distance for a root branch to always have value set to true"); } else if (branch != null && (!branch.getMethodName().equals(methodName) || !branch.getClassName().equals(className))) { throw new IllegalArgumentException("expect explicitly given information about a branch to coincide with the information given by that branch"); } else if (TestCoverageGoal.hasTimeout(result)) { return getTimeoutDistance(result, branch); } else if (branch == null) { return getRootDistance(result, className, methodName); } else { if (value) { if (result.getTrace().getCoveredTrueBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } } else if (result.getTrace().getCoveredFalseBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } ControlFlowDistance nonRootDistance = getNonRootDistance(result, branch, value); return nonRootDistance; } } else { throw new IllegalArgumentException("null given"); } }
InterProceduralControlFlowDistanceCalculator extends ControlFlowDistanceCalculator { public static ControlFlowDistance getDistance( ExecutionResult result, Branch branch, boolean value, String className, String methodName) { if (result != null && className != null && methodName != null) { if (branch == null && !value) { throw new IllegalArgumentException("expect distance for a root branch to always have value set to true"); } else if (branch != null && (!branch.getMethodName().equals(methodName) || !branch.getClassName().equals(className))) { throw new IllegalArgumentException("expect explicitly given information about a branch to coincide with the information given by that branch"); } else if (TestCoverageGoal.hasTimeout(result)) { return getTimeoutDistance(result, branch); } else if (branch == null) { return getRootDistance(result, className, methodName); } else { if (value) { if (result.getTrace().getCoveredTrueBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } } else if (result.getTrace().getCoveredFalseBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } ControlFlowDistance nonRootDistance = getNonRootDistance(result, branch, value); return nonRootDistance; } } else { throw new IllegalArgumentException("null given"); } } }
InterProceduralControlFlowDistanceCalculator extends ControlFlowDistanceCalculator { public static ControlFlowDistance getDistance( ExecutionResult result, Branch branch, boolean value, String className, String methodName) { if (result != null && className != null && methodName != null) { if (branch == null && !value) { throw new IllegalArgumentException("expect distance for a root branch to always have value set to true"); } else if (branch != null && (!branch.getMethodName().equals(methodName) || !branch.getClassName().equals(className))) { throw new IllegalArgumentException("expect explicitly given information about a branch to coincide with the information given by that branch"); } else if (TestCoverageGoal.hasTimeout(result)) { return getTimeoutDistance(result, branch); } else if (branch == null) { return getRootDistance(result, className, methodName); } else { if (value) { if (result.getTrace().getCoveredTrueBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } } else if (result.getTrace().getCoveredFalseBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } ControlFlowDistance nonRootDistance = getNonRootDistance(result, branch, value); return nonRootDistance; } } else { throw new IllegalArgumentException("null given"); } }  }
InterProceduralControlFlowDistanceCalculator extends ControlFlowDistanceCalculator { public static ControlFlowDistance getDistance( ExecutionResult result, Branch branch, boolean value, String className, String methodName) { if (result != null && className != null && methodName != null) { if (branch == null && !value) { throw new IllegalArgumentException("expect distance for a root branch to always have value set to true"); } else if (branch != null && (!branch.getMethodName().equals(methodName) || !branch.getClassName().equals(className))) { throw new IllegalArgumentException("expect explicitly given information about a branch to coincide with the information given by that branch"); } else if (TestCoverageGoal.hasTimeout(result)) { return getTimeoutDistance(result, branch); } else if (branch == null) { return getRootDistance(result, className, methodName); } else { if (value) { if (result.getTrace().getCoveredTrueBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } } else if (result.getTrace().getCoveredFalseBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } ControlFlowDistance nonRootDistance = getNonRootDistance(result, branch, value); return nonRootDistance; } } else { throw new IllegalArgumentException("null given"); } }  static ControlFlowDistance getDistance( ExecutionResult result, Branch branch, boolean value, String className, String methodName); }
InterProceduralControlFlowDistanceCalculator extends ControlFlowDistanceCalculator { public static ControlFlowDistance getDistance( ExecutionResult result, Branch branch, boolean value, String className, String methodName) { if (result != null && className != null && methodName != null) { if (branch == null && !value) { throw new IllegalArgumentException("expect distance for a root branch to always have value set to true"); } else if (branch != null && (!branch.getMethodName().equals(methodName) || !branch.getClassName().equals(className))) { throw new IllegalArgumentException("expect explicitly given information about a branch to coincide with the information given by that branch"); } else if (TestCoverageGoal.hasTimeout(result)) { return getTimeoutDistance(result, branch); } else if (branch == null) { return getRootDistance(result, className, methodName); } else { if (value) { if (result.getTrace().getCoveredTrueBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } } else if (result.getTrace().getCoveredFalseBranches().contains(branch.getActualBranchId())) { return new ControlFlowDistance(0, 0.0D); } ControlFlowDistance nonRootDistance = getNonRootDistance(result, branch, value); return nonRootDistance; } } else { throw new IllegalArgumentException("null given"); } }  static ControlFlowDistance getDistance( ExecutionResult result, Branch branch, boolean value, String className, String methodName);  }