HistoryOverview { public DonutData getDonutData() { int countAll = historyEntry.getSingleResults().size(); if (countAll == 0) { return new DonutData(BigDecimal.ZERO, BigDecimal.ZERO); } double countOk = 0; double countFailed = 0; for (ExecutionResult result : historyEntry.getSingleResults()) { if (ExecutionState.SUCCESS.equals(result.getState())) { countOk++; } else if (ExecutionState.FAILED.equals(result.getState())) { countFailed++; } } BigDecimal percentageOk = BigDecimal.valueOf((countOk / countAll) * 100); BigDecimal percentageFailed = BigDecimal.valueOf((countFailed / countAll) * 100); return new DonutData(percentageOk, percentageFailed); }  @PostConstruct void init(); HistoryEntry getHistory(); String getStart(); String getEnd(); String getDuration(); DonutData getDonutData();  }
@Test public void getDonutData() { HistoryEntryImpl entry = new HistoryEntryImpl(); entry.getSingleResults().add(new ExecutionResult(ExecutionState.SKIPPED, "5s", "", null, null, "path")); entry.getSingleResults().add(new ExecutionResult(ExecutionState.SUCCESS, "5s", "", null, null, "path")); entry.getSingleResults().add(new ExecutionResult(ExecutionState.SUCCESS, "5s", "", null, null, "path")); entry.getSingleResults().add(new ExecutionResult(ExecutionState.FAILED, "5s", "", null, null, "path")); Date now = new Date(); entry.setStart(now); entry.setEnd(now); when(historyUtil.readHistoryEntry(historyResource)).thenReturn(entry); overview.init(); DonutData data = overview.getDonutData(); assertEquals("50", data.getOkLength()); assertEquals("75", data.getFailedLength()); assertEquals("25", data.getFailedRemainder()); assertEquals("50", data.getOkRemainder()); assertEquals("50", data.getPercentageOk()); }