@Test
public void shouldApplyTasksToUser() throws Exception {

    // given
    List<UpgradeTask> expected = new ArrayList<>();
    expected.add(new MockUpgradeTask("1.2.0-PE", "1.2.0-first", 1, USER));
    expected.add(new MockUpgradeTask("1.2.0-PE", "1.2.0-second", 2, USER));
    expected.add(new MockUpgradeTask("1.2.0-PE", "1.2.0-third", 3, USER));
    expected.add(new MockUpgradeTask("1.3.0-PE", "1.3.0-1-fourth", 1, USER));
    expected.add(new MockUpgradeTask("1.4.0-PE", "1.4.0-twelfth", 12, USER));
    expected.add(new MockUpgradeTask("2.12.0-EE", "2.12.0-fourth", 4, USER));
    expected.add(new MockUpgradeTask("10.5.0-EE", "2.12.0-fifth", 5, USER));
    List<UpgradeTask> unexpected = new ArrayList<>();
    unexpected.add(new MockUpgradeTask("1.2.0-PE", "1.2.0-second", 2, VERSION));
    unexpected.add(new MockUpgradeTask("1.3.0-PE", "1.3.0-1-fifth", 5, VERSION));
    unexpected.add(new MockUpgradeTask("1.4.0-PE", "1.4.0-eleventh", 11, VERSION));
    unexpected.add(new MockUpgradeTask("2.12.0-EE", "2.12.0-third", 3, VERSION));
    tasks.addAll(expected);
    tasks.addAll(unexpected);
    // when
    when(repository.isAlreadyApplied(anyString(), any())).thenReturn(false);
    service.upgradeUser("Mr Anonymous");
    // then
    for (UpgradeTask task : expected) {
        final MockUpgradeTask mockTask = (MockUpgradeTask) task;
        assertTrue(mockTask.applied);
    }
    for (UpgradeTask task : unexpected) {
        final MockUpgradeTask mockTask = (MockUpgradeTask) task;
        assertFalse(mockTask.applied);
    }
}