SortParserImpl implements SortParser { @Override public List<SortField> parse(String sortString) { if (Validator.isNull(sortString)) { return Collections.emptyList(); } List<String> list = StringUtil.split(sortString); Stream<String> stream = list.stream(); return stream.map( this::getSortFieldOptional ).flatMap( sortFieldOptional -> sortFieldOptional.map( Stream::of ).orElseGet( Stream::empty ) ).collect( Collectors.toList() ); } SortParserImpl(EntityModel entityModel); @Override List<SortField> parse(String sortString);  }
@Test public void testParseEmpty() { List<SortField> sortFields = _sortParserImpl.parse(""); Assert.assertEquals( "No sort keys should be obtained: " + sortFields, 0, sortFields.size()); }
@Test public void testParseOneField() { List<SortField> sortFields = _sortParserImpl.parse("fieldExternal1"); Assert.assertEquals( "One sort field should be obtained: " + sortFields, 1, sortFields.size()); SortField sortField = sortFields.get(0); Assert.assertEquals( "fieldInternal1", sortField.getSortableFieldName(LocaleUtil.getDefault())); }
@Test public void testParseOnlyComma() { List<SortField> sortFields = _sortParserImpl.parse(","); Assert.assertEquals( "No sort fields should be obtained: " + sortFields, 0, sortFields.size()); }