2 * Sone - ListNotificationTest.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.notify;
20 import static org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.empty;
22 import static org.hamcrest.Matchers.is;
23 import static org.hamcrest.Matchers.not;
24 import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
28 import java.util.Arrays;
29 import java.util.Collection;
31 import net.pterodactylus.util.template.Template;
32 import net.pterodactylus.util.template.TemplateContext;
34 import org.junit.Before;
35 import org.junit.Test;
38 * Unit test for {@link ListNotification}.
40 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
42 public class ListNotificationTest {
44 private final TemplateContext initialContext = new TemplateContext();
45 private final Template template = mock(Template.class);
46 private ListNotification<Object> listNotification;
50 when(template.getInitialContext()).thenReturn(initialContext);
51 listNotification = new ListNotification<Object>("id", "key", template);
55 public void newListNotificationDoesNotContainElements() {
56 assertThat(listNotification.getElements(), empty());
57 assertThat(listNotification.isEmpty(), is(true));
61 public void addingAnElement() {
62 Object newObject = new Object();
63 listNotification.add(newObject);
64 assertThat(listNotification.isEmpty(), is(false));
65 assertThat(listNotification.getElements(), contains(newObject));
69 public void removingAnEelement() {
70 Object newObject = new Object();
71 listNotification.add(newObject);
72 listNotification.remove(newObject);
73 assertThat(listNotification.getElements(), empty());
74 assertThat(listNotification.isEmpty(), is(true));
78 public void settingElements() {
79 Object object1 = new Object();
80 Object object2 = new Object();
81 Collection<Object> elements = Arrays.asList(object1, object2);
82 listNotification.setElements(elements);
83 assertThat(listNotification.getElements(), contains(object1, object2));
87 public void addingElementsChangesHashCode() {
88 int emptyListNoficiationHashCode=listNotification.hashCode();
89 listNotification.add(new Object());
90 assertThat(listNotification.hashCode(), not(is(emptyListNoficiationHashCode)));
94 public void listNotificationsWithDifferentIdsAreNotEqual() {
95 ListNotification<Object> secondListNotification = new ListNotification<Object>("otherId", "key", template);
96 assertThat(listNotification, not(is(secondListNotification)));
100 public void listNotificationsWithDifferentKeysAreNotEqual() {
101 ListNotification<Object> secondListNotification = new ListNotification<Object>("id", "otherKey", template);
102 assertThat(listNotification, not(is(secondListNotification)));