Skip to content

Commit 95f2c7d

Browse files
committed
Fixed note tests
1 parent 30754c0 commit 95f2c7d

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

src/test/java/edu/tamu/app/model/NoteTest.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class NoteTest {
4646
protected static final NoteType TEST_NOTE_TYPE = NoteType.ISSUE;
4747
protected static final NoteType TEST_ALTERNATIVE_NOTE_TYPE = NoteType.MAINTENANCE;
4848
protected static final Calendar TEST_DATE = Calendar.getInstance();
49+
protected Service service1;
50+
protected Service service2;
4951

5052
protected static final Credentials TEST_CREDENTIALS = new Credentials();
5153
{
@@ -68,32 +70,34 @@ public class NoteTest {
6870
@Before
6971
public void setUp() {
7072
testUser = appUserRepo.create(TEST_CREDENTIALS.getUin());
71-
testNote = new Note(TEST_NOTE_TITLE, testUser, TEST_NOTE_TYPE, TEST_NOTE_BODY);
73+
service1 = serviceRepo.create(TEST_SERVICE_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_PUBLIC, TEST_ON_SHORT_LIST, null);
74+
service2 = serviceRepo.create(TEST_ALTERNATIVE_SERVICE_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_PUBLIC, TEST_ON_SHORT_LIST, null);
75+
testNote = noteRepo.create(new Note(TEST_NOTE_TITLE, testUser, TEST_NOTE_TYPE, TEST_NOTE_BODY, service1), TEST_CREDENTIALS);
7276
}
7377

7478
@Test
7579
public void testCreate() {
7680
long initialCount = noteRepo.count();
77-
noteRepo.create(testNote, TEST_CREDENTIALS);
81+
noteRepo.create(new Note(TEST_ALTERNATIVE_NOTE_TITLE, testUser, TEST_NOTE_TYPE, TEST_ALTERNATIVE_NOTE_BODY, service2), TEST_CREDENTIALS);
7882
assertEquals("The number of notes did not increase by one", initialCount + 1, noteRepo.count());
7983
}
8084

8185
@Test(expected = DataIntegrityViolationException.class)
8286
public void testTitleNotNull() {
8387
testNote.setTitle(null);
84-
noteRepo.create(testNote, TEST_CREDENTIALS);
88+
noteRepo.create(new Note(null, testUser, TEST_NOTE_TYPE, TEST_ALTERNATIVE_NOTE_BODY, service2), TEST_CREDENTIALS);
8589
}
8690

8791
@Test(expected = DataIntegrityViolationException.class)
8892
public void testAuthorNotNull() {
8993
TEST_CREDENTIALS.setUin("987654321");
90-
noteRepo.create(testNote, TEST_CREDENTIALS);
94+
noteRepo.create(new Note(TEST_ALTERNATIVE_NOTE_TITLE, null, TEST_NOTE_TYPE, TEST_ALTERNATIVE_NOTE_BODY, service2), TEST_CREDENTIALS);
9195
}
9296

9397
@Test(expected = ConstraintViolationException.class)
9498
public void testTitleNotEmpty() {
9599
testNote.setTitle("");
96-
noteRepo.create(testNote, TEST_CREDENTIALS);
100+
noteRepo.create(new Note("", testUser, TEST_NOTE_TYPE, TEST_ALTERNATIVE_NOTE_BODY, service2), TEST_CREDENTIALS);
97101
}
98102

99103
@Test
@@ -106,19 +110,14 @@ public void testUpdateTitle() {
106110

107111
@Test
108112
public void testUpdateServices() {
109-
Service service1 = serviceRepo.create(TEST_SERVICE_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_PUBLIC, TEST_ON_SHORT_LIST, null);
110-
Service service2 = serviceRepo.create(TEST_ALTERNATIVE_SERVICE_NAME, TEST_SERVICE_STATUS, TEST_IS_AUTO, TEST_IS_PUBLIC, TEST_ON_SHORT_LIST, null);
111-
Set<Service> serviceList1 = new HashSet<Service>(Arrays.asList(service1));
112-
Set<Service> serviceList2 = new HashSet<Service>(Arrays.asList(service1, service2));
113+
113114
Note note = noteRepo.create(testNote, TEST_CREDENTIALS);
114-
note.setServices(serviceList1);
115+
note.setService(service1);
115116
note = noteRepo.save(note);
116-
assertEquals("Note services did not contain the right number of services", 1, note.getServices().size());
117-
assertEquals("Note services not set", true, note.getServices().contains(service1));
118-
note.setServices(serviceList2);
117+
assertEquals("Service was not set", service1, note.getService());
118+
note.setService(service2);
119119
note = noteRepo.save(note);
120-
assertEquals("Note services did not contain the right number of services", 2, note.getServices().size());
121-
assertEquals("Note services not updated", true, note.getServices().contains(service2));
120+
assertEquals("Service was not updated correctly", service2, note.getService());
122121
}
123122

124123
@Test
@@ -187,7 +186,7 @@ public void testTimestampSetOnUpdate() throws InterruptedException {
187186
@Test
188187
public void testDelete() {
189188
long initalCount = noteRepo.count();
190-
Note note = noteRepo.create(testNote, TEST_CREDENTIALS);
189+
Note note = noteRepo.create(new Note(TEST_ALTERNATIVE_NOTE_TITLE, testUser, TEST_NOTE_TYPE, TEST_ALTERNATIVE_NOTE_BODY, service2), TEST_CREDENTIALS);
191190
assertEquals("Note not created", initalCount + 1, noteRepo.count());
192191
noteRepo.delete(note);
193192
assertEquals("Note not deleted", initalCount, noteRepo.count());

0 commit comments

Comments
 (0)