X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FListNotificationTest.java;fp=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fnotify%2FListNotificationTest.java;h=0000000000000000000000000000000000000000;hp=5e40f8140d0424b2ee0681222361a49d28741250;hb=e399e8596825ef7480f9803166f0b41b0cad3391;hpb=91e2eb453b5ad6345cb3587e7cc6326b6c3831f0 diff --git a/src/test/java/net/pterodactylus/sone/notify/ListNotificationTest.java b/src/test/java/net/pterodactylus/sone/notify/ListNotificationTest.java deleted file mode 100644 index 5e40f81..0000000 --- a/src/test/java/net/pterodactylus/sone/notify/ListNotificationTest.java +++ /dev/null @@ -1,120 +0,0 @@ -package net.pterodactylus.sone.notify; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.emptyIterable; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.mockito.hamcrest.MockitoHamcrest.argThat; - -import java.util.Arrays; - -import net.pterodactylus.util.notify.NotificationListener; -import net.pterodactylus.util.template.Template; -import net.pterodactylus.util.template.TemplateContext; - -import org.hamcrest.Matchers; -import org.junit.Test; - -/** - * Unit test for {@link ListNotification}. - */ -public class ListNotificationTest { - - private static final String ID = "notification-id"; - private static final String KEY = "element-key"; - private static final String OTHER_KEY = "other-key"; - - private final Template template = mock(Template.class); - private final TemplateContext templateInitialContext = mock(TemplateContext.class); - private ListNotification listNotification; - - public ListNotificationTest() { - when(template.getInitialContext()).thenReturn(templateInitialContext); - listNotification = new ListNotification<>(ID, KEY, template); - } - - @Test - public void creatingAListNotificationSetsEmptyIterableOnElementKeyInTemplateContext() { - verify(templateInitialContext).set(eq(KEY), argThat(emptyIterable())); - } - - @Test - public void newListNotificationHasNoElement() { - assertThat(listNotification.getElements(), emptyIterable()); - } - - @Test - public void newListNotificationIsEmpty() { - assertThat(listNotification.isEmpty(), is(true)); - } - - @Test - public void listNotificationRetainsSetElements() { - listNotification.setElements(Arrays.asList("a", "b", "c")); - assertThat(listNotification.getElements(), Matchers.contains("a", "b", "c")); - } - - @Test - public void listNotificationRetainsAddedElements() { - listNotification.add("a"); - listNotification.add("b"); - listNotification.add("c"); - assertThat(listNotification.getElements(), Matchers.contains("a", "b", "c")); - } - - @Test - public void listNotificationRemovesCorrectElement() { - listNotification.setElements(Arrays.asList("a", "b", "c")); - listNotification.remove("b"); - assertThat(listNotification.getElements(), Matchers.contains("a", "c")); - } - - @Test - public void removingTheLastElementDismissesTheNotification() { - NotificationListener notificationListener = mock(NotificationListener.class); - listNotification.addNotificationListener(notificationListener); - listNotification.add("a"); - listNotification.remove("a"); - verify(notificationListener).notificationDismissed(listNotification); - } - - @Test - public void dismissingTheListNotificationRemovesAllElements() { - listNotification.setElements(Arrays.asList("a", "b", "c")); - listNotification.dismiss(); - assertThat(listNotification.getElements(), emptyIterable()); - } - - @Test - public void listNotificationWithDifferentElementsIsNotEqual() { - ListNotification secondNotification = new ListNotification(ID, KEY, template); - listNotification.add("a"); - secondNotification.add("b"); - assertThat(listNotification, not(is(secondNotification))); - } - - @Test - public void listNotificationWithDifferentKeyIsNotEqual() { - ListNotification secondNotification = new ListNotification(ID, OTHER_KEY, template); - assertThat(listNotification, not(is(secondNotification))); - } - - @Test - public void copiedNotificationsHaveTheSameHashCode() { - ListNotification secondNotification = new ListNotification(listNotification); - listNotification.add("a"); - secondNotification.add("a"); - listNotification.setLastUpdateTime(secondNotification.getLastUpdatedTime()); - assertThat(listNotification.hashCode(), is(secondNotification.hashCode())); - } - - @Test - public void listNotificationIsNotEqualToOtherObjects() { - assertThat(listNotification, not(is(new Object()))); - } - -}