|
|
@@ -75,6 +75,8 @@ public class VoteControllerTest {
|
|
75
|
75
|
|
|
76
|
76
|
testPoll = new Poll();
|
|
77
|
77
|
testPoll.setId(TEST_ID);
|
|
|
78
|
+
|
|
|
79
|
+ testPoll.setQuestion("Do you like cheese?");
|
|
78
|
80
|
options1 = new HashSet<>();
|
|
79
|
81
|
|
|
80
|
82
|
option1 = new Option();
|
|
|
@@ -126,7 +128,7 @@ public class VoteControllerTest {
|
|
126
|
128
|
.willThrow(new ResourceNotFoundException());
|
|
127
|
129
|
|
|
128
|
130
|
MockHttpServletResponse response = mvc.perform(
|
|
129
|
|
- get("polls/votesBADBAD")
|
|
|
131
|
+ get("/polls/votesBADBAD")
|
|
130
|
132
|
.accept(MediaType.APPLICATION_JSON))
|
|
131
|
133
|
.andReturn().getResponse();
|
|
132
|
134
|
|
|
|
@@ -138,11 +140,17 @@ public class VoteControllerTest {
|
|
138
|
140
|
public void testCreateVoteSuccess() throws Exception {
|
|
139
|
141
|
Vote testVote2 = new Vote();
|
|
140
|
142
|
testVote2.setId(TEST_ID);
|
|
|
143
|
+ testVote2.setOption(option1);
|
|
|
144
|
+
|
|
|
145
|
+ /* Fixed by adding an equals method and hashcode to each object.
|
|
|
146
|
+ * during mocking the 'save' method is checking the absolute equality
|
|
|
147
|
+ * and since it's technically a different object, we have to override the equals method
|
|
|
148
|
+ * to properly compare the objects. */
|
|
141
|
149
|
|
|
142
|
150
|
given(pollRepository.findOne(TEST_ID)).willReturn(testPoll);
|
|
143
|
151
|
given(voteRepository.save(testVote2)).willReturn(testVote2);
|
|
144
|
152
|
|
|
145
|
|
- mvc.perform(post("/polls/1/votes/1")
|
|
|
153
|
+ mvc.perform(post("/polls/1/votes")
|
|
146
|
154
|
.content(asJsonString(testVote2))
|
|
147
|
155
|
.contentType(MediaType.APPLICATION_JSON)
|
|
148
|
156
|
.accept(MediaType.APPLICATION_JSON))
|