@Test public void should_return_a_perf_issue_if_execution_time_is_greater_than_expected() { MaxExecutionTimeVerifier maxExecutionTimeVerifier = MaxExecutionTimeVerifier.INSTANCE; ExecutionTime measuredExecutionTime = new ExecutionTime(188 , TimeUnit.MINUTES); hours = 2; minutes = 3; seconds = 4; milliSeconds = 5; microSeconds = 6; nanoSeconds = 7; PerfIssue perfIssue = maxExecutionTimeVerifier.verifyPerfIssue(annotation, measuredExecutionTime); assertThat(perfIssue).isNotEqualTo(PerfIssue.NONE); String description = perfIssue.getDescription(); assertThat(description).startsWith("Execution time of the test method expected to be less than <2 h 3 m 4 s 5 ms 6 µs 7 ns> but is <3 h 8 m 0 s (11 280 000 000 000 ns)>"); }
@Override public PerfIssue verifyPerfIssue(ExpectMaxExecutionTime annotation, ExecutionTime measuredExecutionTime) { ExecutionTime maxExpectedExecutionTime = buildMaxExpectedExecutionTimeFrom(annotation); if(measuredExecutionTime.isGreaterThan(maxExpectedExecutionTime)) { String description = "Execution time of the test method expected to be less than" + " " + "<" + annotationFormatter.format(annotation) + ">" + " but is " + "<" + executionTimeFormatter.formatAndAppendNanoSeconds(measuredExecutionTime) + ">" + System.lineSeparator() + ExecutionTimeWarning.INSTANCE.toString() ; return new PerfIssue(description); } return PerfIssue.NONE; }
MaxExecutionTimeVerifier implements VerifiablePerformanceIssue<ExpectMaxExecutionTime, ExecutionTime> { @Override public PerfIssue verifyPerfIssue(ExpectMaxExecutionTime annotation, ExecutionTime measuredExecutionTime) { ExecutionTime maxExpectedExecutionTime = buildMaxExpectedExecutionTimeFrom(annotation); if(measuredExecutionTime.isGreaterThan(maxExpectedExecutionTime)) { String description = "Execution time of the test method expected to be less than" + " " + "<" + annotationFormatter.format(annotation) + ">" + " but is " + "<" + executionTimeFormatter.formatAndAppendNanoSeconds(measuredExecutionTime) + ">" + System.lineSeparator() + ExecutionTimeWarning.INSTANCE.toString() ; return new PerfIssue(description); } return PerfIssue.NONE; } }
MaxExecutionTimeVerifier implements VerifiablePerformanceIssue<ExpectMaxExecutionTime, ExecutionTime> { @Override public PerfIssue verifyPerfIssue(ExpectMaxExecutionTime annotation, ExecutionTime measuredExecutionTime) { ExecutionTime maxExpectedExecutionTime = buildMaxExpectedExecutionTimeFrom(annotation); if(measuredExecutionTime.isGreaterThan(maxExpectedExecutionTime)) { String description = "Execution time of the test method expected to be less than" + " " + "<" + annotationFormatter.format(annotation) + ">" + " but is " + "<" + executionTimeFormatter.formatAndAppendNanoSeconds(measuredExecutionTime) + ">" + System.lineSeparator() + ExecutionTimeWarning.INSTANCE.toString() ; return new PerfIssue(description); } return PerfIssue.NONE; } private  MaxExecutionTimeVerifier(); }
MaxExecutionTimeVerifier implements VerifiablePerformanceIssue<ExpectMaxExecutionTime, ExecutionTime> { @Override public PerfIssue verifyPerfIssue(ExpectMaxExecutionTime annotation, ExecutionTime measuredExecutionTime) { ExecutionTime maxExpectedExecutionTime = buildMaxExpectedExecutionTimeFrom(annotation); if(measuredExecutionTime.isGreaterThan(maxExpectedExecutionTime)) { String description = "Execution time of the test method expected to be less than" + " " + "<" + annotationFormatter.format(annotation) + ">" + " but is " + "<" + executionTimeFormatter.formatAndAppendNanoSeconds(measuredExecutionTime) + ">" + System.lineSeparator() + ExecutionTimeWarning.INSTANCE.toString() ; return new PerfIssue(description); } return PerfIssue.NONE; } private  MaxExecutionTimeVerifier(); @Override PerfIssue verifyPerfIssue(ExpectMaxExecutionTime annotation, ExecutionTime measuredExecutionTime); }
MaxExecutionTimeVerifier implements VerifiablePerformanceIssue<ExpectMaxExecutionTime, ExecutionTime> { @Override public PerfIssue verifyPerfIssue(ExpectMaxExecutionTime annotation, ExecutionTime measuredExecutionTime) { ExecutionTime maxExpectedExecutionTime = buildMaxExpectedExecutionTimeFrom(annotation); if(measuredExecutionTime.isGreaterThan(maxExpectedExecutionTime)) { String description = "Execution time of the test method expected to be less than" + " " + "<" + annotationFormatter.format(annotation) + ">" + " but is " + "<" + executionTimeFormatter.formatAndAppendNanoSeconds(measuredExecutionTime) + ">" + System.lineSeparator() + ExecutionTimeWarning.INSTANCE.toString() ; return new PerfIssue(description); } return PerfIssue.NONE; } private  MaxExecutionTimeVerifier(); @Override PerfIssue verifyPerfIssue(ExpectMaxExecutionTime annotation, ExecutionTime measuredExecutionTime); static final MaxExecutionTimeVerifier INSTANCE; }