TranslationComparator implements Comparator<Translation> { @Override public int compare(final Translation o1, final Translation o2) { if (o1 == o2) { return 0; } if (o1 == null) { return 1; } if (o2 == null) { return -1; } if (o1.getLang().equals(o2.getLang())) { return o1.getValue().compareTo(o2.getValue()); } if (o1.getLang().equals(Language.of(""))) { return -1; } else if (o2.getLang().equals(Language.of(""))) { return 1; } if (o1.getLang().equals(Language.of("_"))) { return -1; } else if (o2.getLang().equals(Language.of("_"))) { return 1; } if (o1.getLang().getLang().startsWith("<")) { return -1; } else if (o2.getLang().getLang().startsWith("<")) { return 1; } return o1.getLang().compareTo(o2.getLang()); }  @Override int compare(final Translation o1, final Translation o2); static final TranslationComparator INSTANCE; }
@Test public void testCompare_DE_EN() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de"), "de"), new Translation(Language.of("en"), "en") )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("en"), "en"), new Translation(Language.of("de"), "de") )).isGreaterThan(0); }
@Test public void testCompare_EMPTY_DE() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of(""), "empty"), new Translation(Language.of("de"), "de") )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de"), "de"), new Translation(Language.of(""), "empty") )).isGreaterThan(0); }
@Test public void testCompare_UNDERSCORE_DE() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("_"), "underscore"), new Translation(Language.of("de"), "de") )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de"), "de"), new Translation(Language.of("_"), "underscore") )).isGreaterThan(0); }
@Test public void testCompare_DEFAULT_DE() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("<default>"), "default"), new Translation(Language.of("de"), "de") )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de"), "de"), new Translation(Language.of("<default>"), "default") )).isGreaterThan(0); }
@Test public void testCompare_EMPTY_UNDERSCORE() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of(""), "empty"), new Translation(Language.of("_"), "underscore") )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("_"), "underscore"), new Translation(Language.of(""), "empty") )).isGreaterThan(0); }
@Test public void testCompare_EMPTY_DEFAULT() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of(""), "empty"), new Translation(Language.of("<default>"), "default") )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("<default>"), "default"), new Translation(Language.of(""), "empty") )).isGreaterThan(0); }
@Test public void testCompare_UNDERSCORE_DEFAULT() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("_"), "underscore"), new Translation(Language.of("<default>"), "default") )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("<default>"), "default"), new Translation(Language.of("_"), "underscore") )).isGreaterThan(0); }
@Test public void testCompare_DE_DE() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de"), "de"), new Translation(Language.of("de"), "de") )).isEqualTo(0); }
@Test public void testCompare_DE_DE_AT() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de"), "de"), new Translation(Language.of("de_AT"), "de_AT") )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de_AT"), "de_AT"), new Translation(Language.of("de"), "de") )).isGreaterThan(0); }
@Test public void testCompare_DE_DE_differentValue() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de"), "de"), new Translation(Language.of("de"), "zzz") )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de"), "zzz"), new Translation(Language.of("de"), "de") )).isGreaterThan(0); }
@Test public void testCompare_with_self() { final Translation t= new Translation(Language.of("de"), "de"); assertThat(TRANSLATION_COMPARATOR.compare( t, t )).isEqualTo(0); }
@Test public void testCompare_DE_NULL() { assertThat(TRANSLATION_COMPARATOR.compare( new Translation(Language.of("de"), "de"), null )).isLessThan(0); assertThat(TRANSLATION_COMPARATOR.compare( null, new Translation(Language.of("de"), "de") )).isGreaterThan(0); }
@Test public void testCompare_NULL_NULL() { assertThat(TRANSLATION_COMPARATOR.compare( null, null )).isEqualTo(0); }