Пример #1
0
  @Test
  public void shouldChooseVaderThemeBecauseOfTheContextFiltersDecreeSequence() {
    final String SUNNY = "sunny";
    final String ARISTO = "aristo";
    final String VADER = "vader";

    final DecreeSequence ds142 = mock(DecreeSequence.class);
    final DecreeSequence ds475 = mock(DecreeSequence.class);
    final User currentUser = mock(User.class);
    final PerDecreePreference pref142 = mock(PerDecreePreference.class);
    final PerDecreePreference pref475 = mock(PerDecreePreference.class);

    when(userSession.getCurrentUser()).thenReturn(currentUser);
    when(pref142.getDecreeSequence()).thenReturn(ds142);
    when(pref475.getDecreeSequence()).thenReturn(ds475);
    when(pref142.getTheme()).thenReturn(SUNNY);
    when(pref475.getTheme()).thenReturn(VADER);

    when(userSession.getUserPrefferedTheme()).thenReturn(Optional.of(ARISTO));

    when(contextualFilter.getDecreeSequence()).thenReturn(ds475);
    when(perDecreePreferenceRepository.findByUser(currentUser))
        .thenReturn(asList(pref142, pref475));

    String theme = controller.getCurrentThemeOrElse("aristo");

    assertThat(theme, is(VADER));
  }
Пример #2
0
  @Test
  public void currentUserSessuinShouldBeAskedForTheUserPrefferedThme() {

    when(userSession.getUserPrefferedTheme()).thenReturn(Optional.of("sunny"));

    String currentTheme = controller.getCurrentThemeOrElse("aristo");

    assertThat(currentTheme, is(equalTo(userSession.getUserPrefferedTheme().get())));
  }
Пример #3
0
  @Test
  public void
      ifTheUsersPrefferedThemeIsNotDefinedThenThenTheFirstAvailableThemeIsChoosenAsThePrefferedTheme() {

    when(userSession.getUserPrefferedTheme()).thenReturn(Optional.empty());

    String expected = controller.getThemes().values().iterator().next();

    String currentTheme = controller.getCurrentThemeOrElse("aristo");

    assertThat(currentTheme, is(equalTo(expected)));
  }
Пример #4
0
  @Test
  public void
      ifTheUserPrefferedThemeIsNotInTheListOfPredefinedThemesThentheFirstEntryOfTheMapShouldReturned() {

    when(userSession.getUserPrefferedTheme())
        .thenReturn(Optional.of(controller.getThemes().keySet().iterator().next() + "XXX"));

    String expected = controller.getThemes().values().iterator().next();

    String currentTheme = controller.getCurrentThemeOrElse("aristo");

    assertThat(currentTheme, is(equalTo(expected)));
  }