Skip to content

Commit cd72cd4

Browse files
committed
zombies killed
1 parent 64f5276 commit cd72cd4

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/test/java/org/rulez/demokracia/pdengine/ChoiceDeleteAdminKeyIsUser.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.rulez.demokracia.pdengine;
22

3+
import static org.junit.Assert.assertEquals;
4+
35
import org.junit.Test;
46
import org.rulez.demokracia.pdengine.annotations.TestedBehaviour;
57
import org.rulez.demokracia.pdengine.annotations.TestedFeature;
@@ -50,7 +52,18 @@ public void if_adminKey_is_user_and_canAddin_is_true_then_the_user_who_added_the
5052
() -> voteManager.getChoice(voteId, choiceId)
5153
).assertMessageIs("Illegal choiceId");
5254
}
53-
55+
56+
@TestedBehaviour("if \"user\" is used as adminKey, then the user must be the one who added the choice and canAddIn be true")
57+
@Test
58+
public void deleteChoice_return_an_OK_if_the_choice_is_deleted() {
59+
String voteId = adminInfo.voteId;
60+
Vote vote = voteManager.getVote(voteId);
61+
vote.canAddin = true;
62+
String choiceId = voteManager.addChoice(new VoteAdminInfo(adminInfo.voteId, USER), CHOICE1, TEST_USER_NAME);
63+
String r = voteManager.deleteChoice(new VoteAdminInfo(voteId, USER), choiceId);
64+
assertEquals("OK",r);
65+
}
66+
5467
@TestedBehaviour("if the vote has ballots issued, the choice cannot be deleted")
5568
@Test
5669
public void if_the_vote_has_issued_ballots_then_the_choice_cannot_be_deleted() {

src/test/java/org/rulez/demokracia/pdengine/VoteShowTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.rulez.demokracia.pdengine;
22

33
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.fail;
45

56
import org.json.JSONArray;
67
import org.json.JSONObject;
@@ -59,6 +60,13 @@ public void the_choices_attribute_contains_the_choices_of_the_vote() {
5960

6061
assertEquals(result.getJSONArray("choices").toString(), jsonArray.toString());
6162
}
63+
@Test
64+
public void the_initiator_of_the_choice_is_in_the_json() {
65+
JSONArray jsonArray = vote.createChoicesJson(vote.choices);
66+
JSONObject firstChoice = (JSONObject) jsonArray.get(0);
67+
String initiatorInJson = (String) firstChoice.get("initiator");
68+
assertEquals("user", initiatorInJson);
69+
}
6270

6371
@Test
6472
public void the_canEndorse_attribute_contains_whether_the_voters_endorse_choices_of_the_vote() {

src/test/java/org/rulez/demokracia/types/MatrixKeyTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ public void columnKey_should_be_in_keyCollection_for_setElement() {
2424
@Test
2525
public void rowKey_should_be_in_keyCollection_for_getElement() {
2626
updateMatrixWithNewKey(columnKey);
27-
assertSetElementFailsWith(columnKey,rowKey, "Invalid row key");
27+
assertGetElementFailsWith(columnKey,rowKey, "Invalid row key");
2828
}
2929

3030
@Test
3131
public void columnKey_should_be_in_keyCollection_for_getElement() {
3232
updateMatrixWithNewKey(rowKey);
33-
assertSetElementFailsWith(columnKey,rowKey, "Invalid column key");
33+
assertGetElementFailsWith(columnKey,rowKey, "Invalid column key");
3434
}
3535

3636
@Test
@@ -67,4 +67,12 @@ private void assertSetElementFailsWith(final String columnKey, final String rowK
6767
})
6868
.assertException(IllegalArgumentException.class).assertMessageIs(message);
6969
}
70+
71+
private void assertGetElementFailsWith(final String columnKey, final String rowKey, final String message) {
72+
assertThrows(
73+
() -> {
74+
theMatrix.getElement(columnKey, rowKey);
75+
})
76+
.assertException(IllegalArgumentException.class).assertMessageIs(message);
77+
}
7078
}

0 commit comments

Comments
 (0)