SortConverter { public static List<Sort> convertToSorts(List<String> jmapSorts) { Preconditions.checkNotNull(jmapSorts); return jmapSorts.stream() .map(SortConverter::toSort) .collect(Guavate.toImmutableList()); }  static List<Sort> convertToSorts(List<String> jmapSorts);  }
@Test public void convertToSortsShouldThrowOnNullValue() { expectedException.expect(NullPointerException.class); SortConverter.convertToSorts(null); }
@Test public void convertToSortsShouldReturnEmptyOnEmptyEntry() { assertThat(SortConverter.convertToSorts(ImmutableList.of())) .isEmpty(); }
@Test public void convertToSortsShouldThrowOnNullJmapSort() { List<String> jmapSorts = Lists.newArrayList((String) null); expectedException.expect(NullPointerException.class); SortConverter.convertToSorts(jmapSorts); }
@Test public void convertToSortsShouldThrowOnEmptyJmapSort() { expectedException.expect(IllegalArgumentException.class); SortConverter.convertToSorts(ImmutableList.of("")); }
@Test public void convertToSortsShouldThrowOnUnknownJmapSort() { expectedException.expect(IllegalArgumentException.class); SortConverter.convertToSorts(ImmutableList.of("unknown")); }
@Test public void convertToSortsShouldSupportDate() { assertThat(SortConverter.convertToSorts(ImmutableList.of("date desc"))) .containsExactly(new Sort(SortClause.SentDate, Order.REVERSE)); }
@Test public void convertToSortsShouldSupportId() { assertThat(SortConverter.convertToSorts(ImmutableList.of("id desc"))) .containsExactly(new Sort(SortClause.Id, Order.REVERSE)); }
@Test public void convertToSortsShouldBeDescWhenNoOrderClause() { assertThat(SortConverter.convertToSorts(ImmutableList.of("date"))) .containsExactly(new Sort(SortClause.SentDate, Order.REVERSE)); }
@Test public void convertToSortsShouldThrowWhenOnUnknownOrderClause() { expectedException.expect(IllegalArgumentException.class); SortConverter.convertToSorts(ImmutableList.of("date unknown")); }
@Test public void convertToSortsShouldSupportAscOrder() { assertThat(SortConverter.convertToSorts(ImmutableList.of("date asc"))) .containsExactly(new Sort(SortClause.SentDate, Order.NATURAL)); }
@Test public void convertToSortsShouldThrowWhenJmapSortIsTooLong() { expectedException.expect(IllegalArgumentException.class); SortConverter.convertToSorts(ImmutableList.of("date asc toomuch")); }
@Test public void convertToSortsShouldSupportMultipleSorts() { assertThat(SortConverter.convertToSorts(ImmutableList.of("date asc", "id desc"))) .containsExactly(new Sort(SortClause.SentDate, Order.NATURAL), new Sort(SortClause.Id, Order.REVERSE)); }
@Test public void convertToSortsShouldSupportSubject() { assertThat(SortConverter.convertToSorts(ImmutableList.of("subject desc"))) .containsExactly(new Sort(SortClause.BaseSubject, Order.REVERSE)); }
@Test public void convertToSortsShouldSupportFrom() { assertThat(SortConverter.convertToSorts(ImmutableList.of("from desc"))) .containsExactly(new Sort(SortClause.MailboxFrom, Order.REVERSE)); }
@Test public void convertToSortsShouldSupportTo() { assertThat(SortConverter.convertToSorts(ImmutableList.of("to desc"))) .containsExactly(new Sort(SortClause.MailboxTo, Order.REVERSE)); }
@Test public void convertToSortsShouldSupportSize() { assertThat(SortConverter.convertToSorts(ImmutableList.of("size desc"))) .containsExactly(new Sort(SortClause.Size, Order.REVERSE)); }