AbstractTemplateController extends AbstractBaseController { protected final void parseAndUpdateSortParameters(final BaseCommand command, final UserRepositoryContext userContext) { if (command.getSortType() != null) { userContext.setSortType(command.getSortType()); } else if (userContext.getSortType() == null) { userContext.setSortType(DirEntryComparator.SortType.FULL_NAME); } if (command.getSortMode() != null) { userContext.setSortMode(command.getSortMode()); } else if (userContext.getSortMode() == null) { userContext.setSortMode(DirEntrySorter.SortMode.ASC); } }  @Override final ModelAndView handle(final HttpServletRequest request, final HttpServletResponse response,
                                   final Object cmd, final BindException errors); final void setCacheGateway(final CacheGateway cacheGateway); final void setMaxRevisionsCount(final int maxRevisionsCount); final void setMaxEntriesCount(final int maxEntriesCount); final void setAvailableCharsets(final AvailableCharsets availableCharsets); void setViewName(final String viewName); String getViewName(); static final String ENTRIES_SEARCH_MODE; static final String LOGMESSAGES_SEARCH_MODE; }
@Test public void testParseAndUpdateSortParameters() throws Exception { final UserRepositoryContext userRepositoryContext = new UserRepositoryContext(); final AbstractTemplateController ctrl = new TestController(); final BaseCommand command = new BaseCommand(); assertNull(userRepositoryContext.getSortMode()); assertNull(userRepositoryContext.getSortType()); ctrl.parseAndUpdateSortParameters(command, userRepositoryContext); assertEquals("ASC", userRepositoryContext.getSortMode().toString()); assertEquals("FULL_NAME", userRepositoryContext.getSortType().toString()); command.setSortType(DirEntryComparator.SortType.SIZE); command.setSortMode(DirEntrySorter.SortMode.DESC); ctrl.parseAndUpdateSortParameters(command, userRepositoryContext); assertEquals("DESC", userRepositoryContext.getSortMode().toString()); assertEquals("SIZE", userRepositoryContext.getSortType().toString()); }