View Javadoc
1   package org.itracker.model;
2   
3   import org.junit.After;
4   import org.junit.Before;
5   import org.junit.Ignore;
6   import org.junit.Test;
7   
8   import java.util.Date;
9   
10  import static org.itracker.Assert.assertEntityComparator;
11  import static org.itracker.Assert.assertEntityComparatorEquals;
12  import static org.junit.Assert.*;
13  
14  public class IssueAttachmentTest {
15      private IssueAttachment iss;
16  
17      @Test
18      public void testSetIssue() {
19          try {
20              iss.setIssue(null);
21              fail("did not throw IllegalArgumentException");
22          } catch (IllegalArgumentException e) {
23              assertTrue(true);
24          }
25      }
26  
27      @Test
28      public void testSetOriginalFileName() {
29          try {
30              iss.setOriginalFileName(null);
31              fail("did not throw IllegalArgumentException");
32          } catch (IllegalArgumentException e) {
33              assertTrue(true);
34          }
35      }
36  
37      @Test
38      public void testGetFileExtension() {
39          iss.setOriginalFileName("abc.txt");
40          assertEquals("FileExtension is txt", ".txt", iss.getFileExtension());
41  
42          iss.setOriginalFileName("abc.txt.c");
43          assertEquals("FileExtension is c", ".c", iss.getFileExtension());
44  
45          iss.setOriginalFileName(".c");
46          assertEquals("FileExtension is empty", "", iss.getFileExtension());
47  
48          iss.setOriginalFileName("abc");
49          assertEquals("FileExtension is empty", "", iss.getFileExtension());
50      }
51  
52      @Test
53      public void testSetFileData() {
54          try {
55              iss.setFileData(null);
56              fail("did not throw IllegalArgumentException");
57          } catch (IllegalArgumentException e) {
58              assertTrue(true);
59          }
60      }
61  
62      @Test
63      public void testgetFileData() {
64          try {
65              iss.setFileData(null);
66              fail("did not throw IllegalArgumentException");
67          } catch (IllegalArgumentException e) {
68              assertTrue(true);
69          }
70          assertNull("file data is null", iss.getFileData());
71      }
72  
73      @Test
74      public void testSetType() {
75          try {
76              iss.setType(null);
77              fail("did not throw IllegalArgumentException");
78          } catch (IllegalArgumentException e) {
79              assertTrue(true);
80          }
81      }
82  
83      @Test
84      public void testToString() {
85          assertNotNull("toString", iss.toString());
86  
87      }
88  
89      /**
90       * TODO: does it still fail sometimes?
91       */
92      @Test
93      @Ignore
94      public void testSizeComparator() {
95          final IssueAttachment attA, attB;
96          final Issue issueA, issueB;
97          issueA = new Issue();
98          issueB = new Issue();
99  
100         attA = new IssueAttachment(issueA, "aaa", "type", "desc", 200l);
101         attB = new IssueAttachment(issueB, "bbb", "type", "desc", 200l);
102 
103 
104         assertEntityComparator("size1 comparator: attA, attB",
105                 IssueAttachment.SIZE_COMPARATOR, attA, attB);
106         assertEntityComparator("size1 comparator: attA, null",
107                 IssueAttachment.SIZE_COMPARATOR, attA, null);
108 
109         attA.setSize(attB.getSize());
110 
111         assertEntityComparator("size2 comparator: attA, attB",
112                 IssueAttachment.SIZE_COMPARATOR, attA, attB);
113         assertEntityComparator("size2 comparator: attA, null",
114                 IssueAttachment.SIZE_COMPARATOR, attA, null);
115 
116         attA.setOriginalFileName(attB.getOriginalFileName());
117 
118         assertEntityComparatorEquals("size3 comparator: attA, attB",
119                 IssueAttachment.SIZE_COMPARATOR, attA, attB);
120         assertEntityComparatorEquals("size3 comparator: attA, attA",
121                 IssueAttachment.SIZE_COMPARATOR, attA, attA);
122     }
123 
124     @Test
125     public void testOriginalFilenameComparator() {
126         IssueAttachment attA, attB;
127         Issue issueA, issueB;
128         issueA = new Issue();
129         issueB = new Issue();
130 
131         attA = new IssueAttachment(issueA, "aaa", "type", "desc", 200l);
132         attA.setCreateDate(new Date());
133         attB = new IssueAttachment(issueB, "bbb", "type", "desc", 200l);
134         try {
135             Thread.sleep(1);
136         } catch (InterruptedException e) {
137         }
138         attB.setCreateDate(new Date());
139 
140 
141         assertEntityComparator("filename comparator",
142                 IssueAttachment.ORIGIINAL_FILENAME_COMPARATOR, attA, attB);
143         assertEntityComparator("filename comparator",
144                 IssueAttachment.ORIGIINAL_FILENAME_COMPARATOR, attA, null);
145 
146         attA.setOriginalFileName(attB.getOriginalFileName());
147 
148         assertEntityComparator("filename comparator",
149                 IssueAttachment.ORIGIINAL_FILENAME_COMPARATOR, attA, attB);
150         assertEntityComparator("filename comparator",
151                 IssueAttachment.ORIGIINAL_FILENAME_COMPARATOR, attA, null);
152 
153         attA.setCreateDate(attB.getCreateDate());
154 
155         assertEntityComparatorEquals("filename comparator",
156                 IssueAttachment.ORIGIINAL_FILENAME_COMPARATOR, attA, attB);
157         assertEntityComparatorEquals("filename comparator",
158                 IssueAttachment.ORIGIINAL_FILENAME_COMPARATOR, attA, attA);
159     }
160 
161 
162     @Before
163     public void setUp() throws Exception {
164         iss = new IssueAttachment();
165     }
166 
167     @After
168     public void tearDown() throws Exception {
169         iss = null;
170     }
171 
172 }