@Test(expected = ValidationException.class) public void testValidateToManyTabs() { context.checking(new Expectations() { { oneOf(actionContext).getPrincipal(); will(returnValue(principalMock)); oneOf(principalMock).getId(); will(returnValue(2L)); oneOf(pMapper).execute(with(equalInternally(personRequest))); will(returnValue(personMock)); oneOf(personMock).getTabs(TabGroupType.START); will(returnValue(tabListMock)); oneOf(tabListMock).size(); will(returnValue(Person.TAB_LIMIT)); } }); try { sut.validate(actionContext); } catch (ValidationException ve) { context.assertIsSatisfied(); assertEquals(ve.getMessage(), Person.TAB_LIMIT_MESSAGE); throw ve; } }
@Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Person user = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); if (user.getTabs(TabGroupType.START).size() >= Person.TAB_LIMIT) { throw new ValidationException(Person.TAB_LIMIT_MESSAGE); } if (validateTabName) { if (((String) inActionContext.getParams()).length() > TabTemplate.MAX_TAB_NAME_LENGTH) { throw new ValidationException(TabTemplate.MAX_TAB_NAME_MESSAGE); } } }
AddTabValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Person user = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); if (user.getTabs(TabGroupType.START).size() >= Person.TAB_LIMIT) { throw new ValidationException(Person.TAB_LIMIT_MESSAGE); } if (validateTabName) { if (((String) inActionContext.getParams()).length() > TabTemplate.MAX_TAB_NAME_LENGTH) { throw new ValidationException(TabTemplate.MAX_TAB_NAME_MESSAGE); } } } }
AddTabValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Person user = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); if (user.getTabs(TabGroupType.START).size() >= Person.TAB_LIMIT) { throw new ValidationException(Person.TAB_LIMIT_MESSAGE); } if (validateTabName) { if (((String) inActionContext.getParams()).length() > TabTemplate.MAX_TAB_NAME_LENGTH) { throw new ValidationException(TabTemplate.MAX_TAB_NAME_MESSAGE); } } } AddTabValidation(final FindByIdMapper<Person> inPersonMapper, final boolean inSkipNameCheck);  AddTabValidation(final FindByIdMapper<Person> inPersonMapper); }
AddTabValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Person user = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); if (user.getTabs(TabGroupType.START).size() >= Person.TAB_LIMIT) { throw new ValidationException(Person.TAB_LIMIT_MESSAGE); } if (validateTabName) { if (((String) inActionContext.getParams()).length() > TabTemplate.MAX_TAB_NAME_LENGTH) { throw new ValidationException(TabTemplate.MAX_TAB_NAME_MESSAGE); } } } AddTabValidation(final FindByIdMapper<Person> inPersonMapper, final boolean inSkipNameCheck);  AddTabValidation(final FindByIdMapper<Person> inPersonMapper); @Override void validate(final PrincipalActionContext inActionContext); }
AddTabValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { Person user = personMapper.execute(new FindByIdRequest("Person", inActionContext.getPrincipal().getId())); if (user.getTabs(TabGroupType.START).size() >= Person.TAB_LIMIT) { throw new ValidationException(Person.TAB_LIMIT_MESSAGE); } if (validateTabName) { if (((String) inActionContext.getParams()).length() > TabTemplate.MAX_TAB_NAME_LENGTH) { throw new ValidationException(TabTemplate.MAX_TAB_NAME_MESSAGE); } } } AddTabValidation(final FindByIdMapper<Person> inPersonMapper, final boolean inSkipNameCheck);  AddTabValidation(final FindByIdMapper<Person> inPersonMapper); @Override void validate(final PrincipalActionContext inActionContext);  }