### Question:
LoginAggregator implements Aggregator<String, LoginEvent, LoginRollup> { @Override public LoginRollup apply(final String appId, final LoginEvent loginEvent, final LoginRollup loginRollup) { final String userId = loginEvent.getUserId(); final Map<String, Map<String, Long>> allLogins = loginRollup.getLoginByAppAndUser(); final Map<String, Long> userLogins = allLogins.computeIfAbsent(appId, key -> new HashMap<>()); userLogins.compute(userId, (k, v) -> v == null ? 1L : v + 1L); return loginRollup; }  @Override LoginRollup apply(final String appId,
                           final LoginEvent loginEvent,
                           final LoginRollup loginRollup);  }### Answer:
@Test public void shouldAggregateValues() { final LoginAggregator loginAggregator = new LoginAggregator(); final LoginRollup loginRollup = new LoginRollup(); loginRollup.setLoginByAppAndUser(new HashMap<>()); final String appOne = "app-one"; final String appTwo = "app-two"; final String appThree = "app-three"; final String user1 = "user1"; final String user2 = "user2"; loginAggregator.apply(appOne, login(appOne, user1), loginRollup); loginAggregator.apply(appTwo, login(appTwo, user1), loginRollup); loginAggregator.apply(appThree, login(appThree, user1), loginRollup); assertThat(loginRollup.getLoginByAppAndUser().get(appOne).get(user1), is(1L)); assertThat(loginRollup.getLoginByAppAndUser().get(appTwo).get(user1), is(1L)); assertThat(loginRollup.getLoginByAppAndUser().get(appThree).get(user1), is(1L)); loginAggregator.apply(appOne, login(appOne, user1), loginRollup); loginAggregator.apply(appTwo, login(appTwo, user1), loginRollup); assertThat(loginRollup.getLoginByAppAndUser().get(appOne).get(user1), is(2L)); assertThat(loginRollup.getLoginByAppAndUser().get(appTwo).get(user1), is(2L)); assertThat(loginRollup.getLoginByAppAndUser().get(appThree).get(user1), is(1L)); loginAggregator.apply(appOne, login(appOne, user2), loginRollup); loginAggregator.apply(appTwo, login(appTwo, user2), loginRollup); loginAggregator.apply(appThree, login(appThree, user2), loginRollup); loginAggregator.apply(appOne, login(appOne, user1), loginRollup); loginAggregator.apply(appTwo, login(appTwo, user1), loginRollup); loginAggregator.apply(appThree, login(appThree, user1), loginRollup); assertThat(loginRollup.getLoginByAppAndUser().get(appOne).get(user1), is(3L)); assertThat(loginRollup.getLoginByAppAndUser().get(appTwo).get(user1), is(3L)); assertThat(loginRollup.getLoginByAppAndUser().get(appThree).get(user1), is(2L)); assertThat(loginRollup.getLoginByAppAndUser().get(appOne).get(user2), is(1L)); assertThat(loginRollup.getLoginByAppAndUser().get(appTwo).get(user2), is(1L)); assertThat(loginRollup.getLoginByAppAndUser().get(appThree).get(user2), is(1L)); }