Remediation { public DebtRemediationFunction remediationFunction(DebtRemediationFunctions debt) { if (func.startsWith("Constant")) { return debt.constantPerIssue(constantCost.replace("mn", "min")); } if ("Linear".equals(func)) { return debt.linear(linearFactor.replace("mn", "min")); } return debt.linearWithOffset(linearFactor.replace("mn", "min"), linearOffset.replace("mn", "min")); }  DebtRemediationFunction remediationFunction(DebtRemediationFunctions debt);  }
@Test public void testRemediationFunctionConstantPerIssue() { remediation.func = "Constant issue"; remediation.constantCost = "3 mn"; DebtRemediationFunctions functions = mock(DebtRemediationFunctions.class); DebtRemediationFunction function = mock(DebtRemediationFunction.class); when(functions.constantPerIssue(eq(remediation.constantCost))).thenReturn(function); when(function.coefficient()).thenReturn("3 min"); remediation.remediationFunction(functions); verify(functions).constantPerIssue("3 min"); assertEquals("3 min",function.coefficient()); }
@Test public void testRemediationFunctionLinear() { remediation.func = "Linear"; remediation.linearFactor = "2 mn"; DebtRemediationFunctions functions = mock(DebtRemediationFunctions.class); DebtRemediationFunction function = mock(DebtRemediationFunction.class); when(functions.linear(eq(remediation.linearFactor))).thenReturn(function); when(function.coefficient()).thenReturn("2 min"); remediation.remediationFunction(functions); verify(functions).linear("2 min"); assertEquals("2 min",function.coefficient()); }
@Test public void testRemediationFunctionlinearWithOffset() { remediation.func = "somethingElse"; remediation.linearFactor = "2 mn"; remediation.linearOffset = "2 mn"; DebtRemediationFunctions functions = mock(DebtRemediationFunctions.class); DebtRemediationFunction function = mock(DebtRemediationFunction.class); when(functions.linearWithOffset(eq(remediation.linearFactor), eq(remediation.linearOffset))).thenReturn(function); when(function.coefficient()).thenReturn("2 min"); remediation.remediationFunction(functions); verify(functions).linearWithOffset("2 min", "2 min"); assertEquals("2 min",function.coefficient()); }