View Javadoc
1   package org.itracker.model;
2   
3   import org.itracker.model.Notification.Role;
4   import org.junit.After;
5   import org.junit.Before;
6   import org.junit.Test;
7   
8   import static org.itracker.Assert.assertEntityComparator;
9   import static org.itracker.Assert.assertEntityComparatorEquals;
10  import static org.junit.Assert.*;
11  
12  public class NotificationTest {
13      private Notification not;
14  
15      @Test
16      public void testSetIssue() {
17          try {
18              not.setIssue(null);
19              fail("did not throw IllegalArgumentException");
20          } catch (IllegalArgumentException e) {
21              assertTrue(true);
22          }
23      }
24  
25      @Test
26      public void testSetUser() {
27          try {
28              not.setUser(null);
29              fail("did not throw IllegalArgumentException");
30          } catch (IllegalArgumentException e) {
31              assertTrue(true);
32          }
33      }
34  
35      /**
36       * TODO remove method from Notification
37       */
38      @SuppressWarnings("deprecation")
39      @Test
40      public void testSetNotificationRole() {
41          not.setNotificationRole(1);
42          assertEquals(1, not.getNotificationRole());
43          not.setNotificationRole(10000);
44          assertEquals(-1, not.getNotificationRole());
45      }
46  
47      @Test
48      public void testToString() {
49          assertNotNull("toString", not.toString());
50      }
51  
52      @Test
53      public void testUserComparator() {
54          Notification entityA = new Notification(new User("aaa", "", "a", "a", "a@a.com", false), new Issue(), Role.ANY);
55          Notification entityB = new Notification(new User("bbb", "", "b", "b", "b@b.com", false), new Issue(), Role.ANY);
56  
57          assertEntityComparator("user comparator", Notification.USER_COMPARATOR, entityA, entityB);
58          assertEntityComparator("user comparator", Notification.USER_COMPARATOR, entityA, null);
59  
60          entityA.setUser(entityB.getUser());
61          assertEntityComparatorEquals("user comparator", Notification.USER_COMPARATOR, entityA, entityB);
62          assertEntityComparatorEquals("user comparator", Notification.USER_COMPARATOR, entityA, entityA);
63  
64      }
65  
66      @Test
67      public void testIssueUserRoleComparator() {
68          Issue issueA = new Issue();
69          issueA.setId(1);
70          Issue issueB = new Issue();
71          issueB.setId(2);
72          User userA = new User("aaa", "", "a", "a", "a@a.com", false);
73          User userB = new User("bbb", "", "b", "b", "b@b.com", false);
74          Notification entityA = new Notification(userA, issueA, Role.ANY);
75          Notification entityB = new Notification(userA, issueB, Role.ANY);
76  
77          assertEntityComparator("issue user role comparator", Notification.ISSUE_USER_ROLE_COMPARATOR, entityA, entityB);
78          assertEntityComparator("issue user role comparator", Notification.ISSUE_USER_ROLE_COMPARATOR, entityA, null);
79  
80          entityA.setIssue(entityB.getIssue());
81          entityB.setUser(userB);
82  
83          assertEntityComparator("issue user role comparator", Notification.ISSUE_USER_ROLE_COMPARATOR, entityA, entityB);
84          assertEntityComparator("issue user role comparator", Notification.ISSUE_USER_ROLE_COMPARATOR, entityA, null);
85  
86          entityB.setUser(userA);
87          entityB.setRole(Role.CREATOR);
88  
89          assertEntityComparator("issue user role comparator", Notification.ISSUE_USER_ROLE_COMPARATOR, entityA, entityB);
90          assertEntityComparator("issue user role comparator", Notification.ISSUE_USER_ROLE_COMPARATOR, entityA, null);
91  
92          entityA.setRole(entityB.getRole());
93          assertEntityComparatorEquals("issue user role comparator", Notification.ISSUE_USER_ROLE_COMPARATOR, entityA, entityB);
94          assertEntityComparatorEquals("issue user role comparator", Notification.ISSUE_USER_ROLE_COMPARATOR, entityA, entityA);
95  
96      }
97  
98      @Test
99      public void testRoleComparator() {
100         Issue issueA = new Issue();
101         issueA.setId(1);
102         Issue issueB = new Issue();
103         issueB.setId(2);
104 
105         User userA = new User("aaa", "", "a", "a", "a@a.com", false);
106         User userB = new User("bbb", "", "b", "b", "b@b.com", false);
107         Notification entityA = new Notification(userA, issueA, null);
108         Notification entityB = new Notification(userB, issueA, Role.CREATOR);
109 
110         assertEntityComparator("role comparator", Notification.TYPE_COMPARATOR, entityA, entityB);
111         assertEntityComparator("role comparator", Notification.TYPE_COMPARATOR, entityA, null);
112 
113         entityA.setRole(Role.ANY);
114 
115         assertEntityComparator("role comparator", Notification.TYPE_COMPARATOR, entityA, entityB);
116         assertEntityComparator("role comparator", Notification.TYPE_COMPARATOR, entityA, null);
117 
118         entityB.setRole(entityA.getRole());
119 
120         assertEntityComparatorEquals("role comparator", Notification.TYPE_COMPARATOR, entityA, entityB);
121         assertEntityComparatorEquals("role comparator", Notification.TYPE_COMPARATOR, entityA, entityA);
122 
123     }
124 
125     @Before
126     public void setUp() throws Exception {
127         not = new Notification();
128     }
129 
130     @After
131     public void tearDown() throws Exception {
132         not = null;
133     }
134 
135 }