@Test public void shouldReturnSortedRoles() { UserModel foo = new UserModel(new User("foo", new ArrayList<>(), "foo@bar.com", false), Arrays.asList("bbb", "aaa", "BBB"), true); assertThat(foo.getRoles(), is(Arrays.asList("BBB", "aaa", "bbb"))); } }
@Test public void shouldUnderstandSplittingMatcherString() { User user = new User("UserName", new String[]{"A", "b"}, "user@mail.com", true); assertThat(user.getMatchers(), is(Arrays.asList("A", "b"))); user = new User("UserName", new String[]{"A,b"}, "user@mail.com", true); assertThat(user.getMatchers(), is(Arrays.asList("A", "b"))); user = new User("UserName", new String[]{""}, "user@mail.com", true); List<String> matchers = Collections.emptyList(); assertThat(user.getMatchers(), is(matchers)); user = new User("UserName", new String[]{"b,A"}, "user@mail.com", true); assertThat(user.getMatchers(), is(Arrays.asList("A", "b"))); }
@Test public void shouldReturnFalseWhenEmailIsEmpty() { assertThat( new User("UserName", new String[]{"README"}, null, true).matchNotification(null, StageEvent.All, null), is(false)); assertThat(new User("UserName", new String[]{"README"}, "", true).matchNotification(null, StageEvent.All, null), is(false)); }
@Test public void shouldValidateEmailLesserThan255() throws Exception { user = new User("UserName", new String[]{"Jez,Pavan"}, "user@mail.com", true); user.validateEmail(); }
@Test public void shouldValidateWhenLoginNameExists() throws Exception { user = new User("bob", new String[]{"Jez,Pavan"}, "user@mail.com", true); user.validateLoginName(); }
@Test(expected = ValidationException.class) public void shouldValidateLoginNameIsNotBlank() throws Exception { user = new User("", new String[]{"Jez,Pavan"}, "user@mail.com", true); user.validateLoginName(); }
@Test public void shouldPopulateEmptyListWhenMatcherDoesNotInitialized() throws Exception { user = new User("UserName", new String[]{""}, "user@mail.com", true); HashMap<String, Object> data = new HashMap<>(); user.populateModel(data); Object value = data.get("matchers"); assertThat(value, is(new Matcher(""))); }
@Test public void shouldPopulateMatchers() throws Exception { user = new User("UserName", new String[]{"Jez,Pavan"}, "user@mail.com", true); HashMap<String, Object> data = new HashMap<>(); user.populateModel(data); Object value = data.get("matchers"); assertThat(value, is(new Matcher("Jez,Pavan"))); }
public static User withName(String username) { User user = new User(username); user.setEmail(String.format("%s@no-reply.com", username)); user.setEmailMe(true); user.setMatcher(String.format("awesome, %s", username)); user.setDisplayName(username); return user; } }
@Test public void shouldAddMultiple() throws Exception { user = new User("UserName", new String[]{" JH ,Pavan,JEZ,"}, "user@mail.com", true); assertThat(user.matcher(), is(new Matcher("JH,Pavan,JEZ"))); }
@Test public void shouldInvalidateEmailWhenEmailIsNotValid() throws Exception { user = new User("UserName", new String[]{"Jez,Pavan"}, "mail.com", true); try { user.validateEmail(); fail("validator should capture the email"); } catch (ValidationException ignored) { } }
@Test public void shouldTrimTheUserNameAndMatcher() throws Exception { user = new User(" UserName ","Full User Name", new String[]{" README "}, " user@mail.com ", true); assertThat(user.getName(), is("UserName")); assertThat(user.getMatcher(), is(("README"))); assertThat(user.getEmail(), is("user@mail.com")); assertThat(user.getDisplayName(), is("Full User Name")); }
@Test public void shouldNotMatchWhenUserDidNotSetUpTheMatcher() throws Exception { materialRevisions = new MaterialRevisions(new MaterialRevision(MaterialsMother.svnMaterial(), aCheckIn("100", "readme"))); assertThat(new User("UserName", new String[]{null}, "user@mail.com", true).matchModification(materialRevisions), is(false)); assertThat(new User("UserName", new String[]{""}, "user@mail.com", true).matchModification(materialRevisions), is(false)); }
@Test public void shouldThrowExceptionIfFilterWithAllEventAlreadyExist() { User user = new User("foo"); user.addNotificationFilter(new NotificationFilter("cruise", "dev", StageEvent.All, false)); try { user.addNotificationFilter(new NotificationFilter("cruise", "dev", StageEvent.Fixed, false)); fail("shouldThrowExceptionIfFilterWithAllEventAlreadyExist"); } catch (Exception e) { assertThat(e.getMessage(), containsString("Duplicate notification filter")); } }
@Test public void shouldInvalidateEmailMoreThan255Of() throws Exception { user = new User("UserName", new String[]{"Jez,Pavan"}, chars(256), true); try { user.validateEmail(); fail("validator should capture the email"); } catch (ValidationException ignored) { } }
@Test public void shouldThrowExceptionIfFilterWithSameEventAlreadyExist() { User user = new User("foo"); user.addNotificationFilter(new NotificationFilter("cruise", "dev", StageEvent.Fixed, false)); try { user.addNotificationFilter(new NotificationFilter("cruise", "dev", StageEvent.Fixed, false)); fail("shouldThrowExceptionIfFilterWithSameEventAlreadyExist"); } catch (Exception e) { assertThat(e.getMessage(), containsString("Duplicate notification filter")); } }
@Test public void shouldInvalidateMatcherMoreThan255Of() throws Exception { user = new User("UserName", new String[]{onlyChars(200), onlyChars(55)}, "user@mail.com", true); try { user.validateMatcher(); fail("validator should capture the matcher"); } catch (ValidationException ignored) { } }
@Test public void shouldReturnTrueWhenNotificationFilterMatchesAnyCheckinOnGivenStageFixed() { materialRevisions = new MaterialRevisions(new MaterialRevision(MaterialsMother.svnMaterial(), aCheckIn("100", "xyz"))); user = new User("UserName", new String[]{"README"}, "user@mail.com", true); user.setNotificationFilters( Arrays.asList(new NotificationFilter("cruise", "dev", StageEvent.Fixed, false))); assertThat( user.matchNotification(new StageConfigIdentifier("cruise", "dev"), StageEvent.Fixed, materialRevisions), is(true)); }
@Test public void shouldReturnTrueWhenNotificationFilterMatchesMyCheckinOnGivenStageFixed() { materialRevisions = new MaterialRevisions(new MaterialRevision(MaterialsMother.svnMaterial(), aCheckIn("100", "readme"))); user = new User("UserName", new String[]{"README"}, "user@mail.com", true); user.setNotificationFilters( Arrays.asList(new NotificationFilter("cruise", "dev", StageEvent.Fixed, true))); assertThat( user.matchNotification(new StageConfigIdentifier("cruise", "dev"), StageEvent.Fixed, materialRevisions), is(true)); }