SecurityAnalysisResultComparisonWriter implements AutoCloseable { public SecurityAnalysisResultComparisonWriter write(Boolean computationOk1, Boolean computationOk2, boolean equivalent) { checkInput(computationOk1, computationOk2); try { formatter = contingency == null ? formatter.writeEmptyCell() : formatter.writeCell(contingency); formatter = computationOk1 == null ? formatter.writeEmptyCells(1) : formatter.writeCell(getStatus(computationOk1)); formatter = computationOk2 == null ? formatter.writeEmptyCells(1) : formatter.writeCell(getStatus(computationOk2)); formatter.writeEmptyCells(11); formatter.writeCell(getComparison(equivalent)); } catch (IOException e) { LOGGER.error("Error writing security analysis results computation status comparison: {}", e.getMessage()); } return this; } SecurityAnalysisResultComparisonWriter(Writer writer); void setContingency(String contingency); SecurityAnalysisResultComparisonWriter write(Boolean computationOk1, Boolean computationOk2, boolean equivalent); SecurityAnalysisResultComparisonWriter write(LimitViolation violation1, LimitViolation violation2, boolean equivalent); SecurityAnalysisResultComparisonWriter write(List<String> actions1, List<String> actions2, boolean equivalent); @Override void close();  }
@Test public void write() { String content = String.join(System.lineSeparator(), "Security Analysis Results Comparison", String.join(";", "Contingency", "StatusResult1", "StatusResult2", "Equipment", "End", "ViolationType", "ViolationNameResult1", "ValueResult1", "LimitResult1", "ViolationNameResult2", "ValueResult2", "LimitResult2", "ActionsResult1", "ActionsResult2", "Comparison"), String.join(";", "", "converge", "converge", "", "", "", "", "", "", "", "", "", "", "", "equivalent"), String.join(";", "", "", "", "VL1", "", LimitViolationType.HIGH_VOLTAGE.name(), "", String.format(Locale.getDefault(), "%g", 250.0), String.format(Locale.getDefault(), "%g", 200.0), "", String.format(Locale.getDefault(), "%g", 250.0), String.format(Locale.getDefault(), "%g", 200.0), "", "", "equivalent"), String.join(";", "contingency", "converge", "converge", "", "", "", "", "", "", "", "", "", "", "", "equivalent"), String.join(";", "contingency", "", "", "VL1", "", LimitViolationType.HIGH_VOLTAGE.name(), "", String.format(Locale.getDefault(), "%g", 250.0), String.format(Locale.getDefault(), "%g", 200.0), "", String.format(Locale.getDefault(), "%g", 250.0), String.format(Locale.getDefault(), "%g", 200.0), "", "", "equivalent"), String.join(";", "contingency", "", "", "NHV1_NHV2_1", Branch.Side.ONE.name(), LimitViolationType.CURRENT.name(), "PermanentLimit", String.format(Locale.getDefault(), "%g", 1100.0), String.format(Locale.getDefault(), "%g", 1000.0), "PermanentLimit", String.format(Locale.getDefault(), "%g", 1100.09), String.format(Locale.getDefault(), "%g", 1000.0), "", "", "equivalent"), String.join(";", "contingency", "", "", "", "", "", "", "", "", "", "", "", actions.toString(), actions.toString(), "equivalent")); comparisonWriter.write(true, true, true); comparisonWriter.write(vlViolation, vlViolation, true); comparisonWriter.write(Collections.emptyList(), Collections.emptyList(), true); comparisonWriter.setContingency("contingency"); comparisonWriter.write(true, true, true); comparisonWriter.write(vlViolation, vlViolation, true); comparisonWriter.write(lineViolation, similarLineViolation, true); comparisonWriter.write(actions, actions, true); assertEquals(content, writer.toString().trim()); }
@Test public void nullInput() { try { comparisonWriter.write((Boolean) null, null, true); fail(); } catch (Exception ignored) { } try { comparisonWriter.write((LimitViolation) null, null, true); fail(); } catch (Exception ignored) { } try { comparisonWriter.write((List<String>) null, null, true); fail(); } catch (Exception ignored) { } }