|
|
@@ -1,6 +1,7 @@
|
|
1
|
1
|
package io.zipcoder.tc_spring_poll_application.controllers;
|
|
2
|
2
|
|
|
3
|
3
|
import io.zipcoder.tc_spring_poll_application.domain.Poll;
|
|
|
4
|
+import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
|
|
4
|
5
|
import io.zipcoder.tc_spring_poll_application.repositories.PollRepository;
|
|
5
|
6
|
import org.junit.Before;
|
|
6
|
7
|
import org.junit.Test;
|
|
|
@@ -15,6 +16,7 @@ import java.util.List;
|
|
15
|
16
|
import java.util.Optional;
|
|
16
|
17
|
import java.util.regex.Pattern;
|
|
17
|
18
|
|
|
|
19
|
+import static junit.framework.TestCase.fail;
|
|
18
|
20
|
import static org.junit.Assert.assertEquals;
|
|
19
|
21
|
import static org.junit.Assert.assertTrue;
|
|
20
|
22
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
@@ -51,6 +53,9 @@ public class PollControllerTest {
|
|
51
|
53
|
// PUT update poll
|
|
52
|
54
|
when(pollRepo.save(any(Poll.class))).thenAnswer(inv -> inv.getArgument(0));
|
|
53
|
55
|
|
|
|
56
|
+ when(pollRepo.existsById(10L)).thenReturn(true);
|
|
|
57
|
+ when(pollRepo.existsById(999L)).thenReturn(false);
|
|
|
58
|
+
|
|
54
|
59
|
// when(pollRepo::save)
|
|
55
|
60
|
// .onSuccess(HttpStatus.CREATED)
|
|
56
|
61
|
// .onFail(HttpStatus.BAD_REQUEST);
|
|
|
@@ -125,4 +130,21 @@ public class PollControllerTest {
|
|
125
|
130
|
verify(pollRepo).deleteById(anyLong());
|
|
126
|
131
|
assertEquals(expected, actual);
|
|
127
|
132
|
}
|
|
|
133
|
+
|
|
|
134
|
+ @Test
|
|
|
135
|
+ public void testVerifyPoll() {
|
|
|
136
|
+
|
|
|
137
|
+ Long exists = 10L;
|
|
|
138
|
+
|
|
|
139
|
+ try {
|
|
|
140
|
+ pollCtrl.verifyPoll(exists);
|
|
|
141
|
+ } catch (ResourceNotFoundException rnfe) {
|
|
|
142
|
+ fail();
|
|
|
143
|
+ }
|
|
|
144
|
+ }
|
|
|
145
|
+
|
|
|
146
|
+ @Test(expected = ResourceNotFoundException.class)
|
|
|
147
|
+ public void testVerifyPollNotFound() {
|
|
|
148
|
+ pollCtrl.verifyPoll(999L);
|
|
|
149
|
+ }
|
|
128
|
150
|
}
|