/** * Notifies listeners about profile update. * * @param old * Old profile instance. * @param updated * Updated profile instance. */ private void publishProfileUpdateEvent(Profile old, Profile updated) { ProfileUpdateEvent profileUpdateEvent = new ProfileUpdateEvent(this, old, updated); eventPublisher.publishEvent(profileUpdateEvent); }
@Test(expectedExceptions = IllegalArgumentException.class) public void idsNotMatching() { when(updated.getId()).thenReturn(ID); when(old.getId()).thenReturn("smth"); new ProfileUpdateEvent(this, old, updated); } }
@Test public void noChange() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); doReturn(Collections.singletonList(assignment)).when(oldProfileData).getData(SensorAssignmentProfileData.class); doReturn(Collections.singletonList(assignment)).when(updatedProfileData).getData(SensorAssignmentProfileData.class); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> removed = event.getRemovedSensorAssignments(); assertThat(removed, is(empty())); }
@Test public void wasActive() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); boolean activated = event.isProfileActivated(); assertThat(activated, is(false)); }
@Test public void activated() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); doReturn(Collections.singletonList(assignment)).when(oldProfileData).getData(SensorAssignmentProfileData.class); doReturn(Collections.singletonList(assignment)).when(updatedProfileData).getData(SensorAssignmentProfileData.class); when(old.isActive()).thenReturn(false); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> removed = event.getRemovedSensorAssignments(); assertThat(removed, is(empty())); }
@Test public void noChange() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); doReturn(Collections.singletonList(assignment)).when(oldProfileData).getData(SensorAssignmentProfileData.class); doReturn(Collections.singletonList(assignment)).when(updatedProfileData).getData(SensorAssignmentProfileData.class); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> added = event.getAddedSensorAssignments(); assertThat(added, is(empty())); }
@Test public void activated() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); when(old.isActive()).thenReturn(false); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); boolean activated = event.isProfileActivated(); assertThat(activated, is(true)); }
@Test public void stillActive() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); boolean deactivated = event.isProfileDeactivated(); assertThat(deactivated, is(false)); } }
@Test public void deactivated() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); doReturn(Collections.singletonList(assignment)).when(oldProfileData).getData(SensorAssignmentProfileData.class); doReturn(Collections.singletonList(assignment)).when(updatedProfileData).getData(SensorAssignmentProfileData.class); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(false); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> added = event.getAddedSensorAssignments(); assertThat(added, is(empty())); }
@Test public void deactivated() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(false); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); boolean deactivated = event.isProfileDeactivated(); assertThat(deactivated, is(true)); }
@Test public void removedAssignments() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); doReturn(Collections.singletonList(assignment)).when(oldProfileData).getData(SensorAssignmentProfileData.class); doReturn(Collections.<AbstractClassSensorAssignment<?>> emptyList()).when(updatedProfileData).getData(SensorAssignmentProfileData.class); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> removed = event.getRemovedSensorAssignments(); assertThat(removed, hasSize(1)); assertThat(removed, hasItem(assignment)); }
@Test public void addedAssignments() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); doReturn(Collections.<AbstractClassSensorAssignment<?>> emptyList()).when(oldProfileData).getData(SensorAssignmentProfileData.class); doReturn(Collections.singletonList(assignment)).when(updatedProfileData).getData(SensorAssignmentProfileData.class); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> added = event.getAddedSensorAssignments(); assertThat(added, hasSize(1)); assertThat(added, hasItem(assignment)); }
@Test public void wasNotActive() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); when(old.isActive()).thenReturn(false); when(updated.isActive()).thenReturn(false); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); boolean deactivated = event.isProfileDeactivated(); assertThat(deactivated, is(false)); }
@Test public void stillNotActive() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); when(old.isActive()).thenReturn(false); when(updated.isActive()).thenReturn(false); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); boolean activated = event.isProfileActivated(); assertThat(activated, is(false)); } }
@Test public void deactivated() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); doReturn(Collections.singletonList(assignment)).when(oldProfileData).getData(SensorAssignmentProfileData.class); doReturn(Collections.singletonList(assignment)).when(updatedProfileData).getData(SensorAssignmentProfileData.class); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(false); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> removed = event.getRemovedSensorAssignments(); assertThat(removed, hasSize(1)); assertThat(removed, hasItem(assignment)); }
@Test public void activated() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); doReturn(Collections.singletonList(assignment)).when(oldProfileData).getData(SensorAssignmentProfileData.class); doReturn(Collections.singletonList(assignment)).when(updatedProfileData).getData(SensorAssignmentProfileData.class); when(old.isActive()).thenReturn(false); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> added = event.getAddedSensorAssignments(); assertThat(added, hasSize(1)); assertThat(added, hasItem(assignment)); }
@Test public void wrongProfileData() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); when(oldProfileData.isOfType(SensorAssignmentProfileData.class)).thenReturn(false); when(updatedProfileData.isOfType(SensorAssignmentProfileData.class)).thenReturn(false); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> removed = event.getRemovedSensorAssignments(); assertThat(removed, is(empty())); } }
@Test public void wrongProfileData() { when(old.getId()).thenReturn(ID); when(updated.getId()).thenReturn(ID); when(oldProfileData.isOfType(SensorAssignmentProfileData.class)).thenReturn(false); when(updatedProfileData.isOfType(SensorAssignmentProfileData.class)).thenReturn(false); when(old.isActive()).thenReturn(true); when(updated.isActive()).thenReturn(true); ProfileUpdateEvent event = new ProfileUpdateEvent(this, old, updated); Collection<AbstractClassSensorAssignment<?>> added = event.getAddedSensorAssignments(); assertThat(added, is(empty())); } }