ConfigProblem implements Comparable<ConfigProblem> { @Override public int compareTo(@Nonnull ConfigProblem that) { if (that.isError() && !isError()) { return 1; } if (isError() && !that.isError()) { return -1; } if (getSource() == null) { if (that.getSource() != null) { return -1; } } else if (that.getSource() == null) { return 1; } else { int cmp = getSource().getSourceName().compareTo(that.getSource().getSourceName()); if (cmp != 0) { return cmp; } } return getMessage().compareTo(that.getMessage()); } ConfigProblem(@Nullable ConfigPart source,
            @NotNull
            @Nls(capitalization = Nls.Capitalization.Sentence)
            String message,
            boolean error); @Nullable ConfigPart getSource(); @NotNull @Nls(capitalization = Nls.Capitalization.Sentence) String getMessage(); boolean isError(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode(); @Override int compareTo(@Nonnull ConfigProblem that);  }
@Test void compareTo_err1() { MockConfigPart part = new MockConfigPart(); ConfigProblem cpF1 = new ConfigProblem(part, "Abc", false); ConfigProblem cpT1 = new ConfigProblem(part, "Abc", true); ConfigProblem cpF2 = new ConfigProblem(part, "Abc", false); ConfigProblem cpT2 = new ConfigProblem(part, "Abc", true); assertEquals( 1, cpF1.compareTo(cpT1) ); assertEquals( -1, cpT1.compareTo(cpF1) ); assertEquals( 0, cpT1.compareTo(cpT2) ); assertEquals( 0, cpT2.compareTo(cpT1) ); assertEquals( 0, cpF2.compareTo(cpF1) ); }
@Test void compareTo_err2() { MockConfigPart part = new MockConfigPart(); ConfigProblem cpF1 = new ConfigProblem(part, "Abc", false); ConfigProblem cpF2 = new ConfigProblem(part, "Def", false); ConfigProblem cpT1 = new ConfigProblem(part, "Abc", true); ConfigProblem cpT2 = new ConfigProblem(part, "Def", true); assertThat(cpF1.compareTo(cpF2), lessThan(0)); assertThat(cpF2.compareTo(cpF1), greaterThan(0)); assertThat(cpT1.compareTo(cpT2), lessThan(0)); assertThat(cpT2.compareTo(cpT1), greaterThan(0)); }