Changed the usage of test from (junit 3 to 4) from extend to @Test.

Voter-Registry
Vladimir Eliezer Tokarev 2016-03-05 06:38:12 -08:00
parent 6d807cdd4d
commit 4fac4bbb8c
4 changed files with 16 additions and 10 deletions

View File

@ -125,14 +125,14 @@ public class Registry implements VoterRegistry{
} }
@Override @Override
public void getPersonIDDetails(VoterID voterID, RegistryCallBack callback) { public void getVoter(VoterID voterID, RegistryCallBack callback) {
List<String> addVoterTags = new ArrayList<String>() {{ List<String> addVoterTags = new ArrayList<String>() {{
add(RegistryTags.ID_TAG + voterID.getId()); add(RegistryTags.ID_TAG + voterID.getId());
add(RegistryTags.VOTER_ENTRY_TAG); add(RegistryTags.VOTER_ENTRY_TAG);
}}; }};
bulletinBoardClient.readMessages(MessageCollectionUtils.generateFiltersFromTags(addVoterTags), bulletinBoardClient.readMessages(MessageCollectionUtils.generateFiltersFromTags(addVoterTags),
new LatestMessagesCallBack(callback, signers, "getPersonIDDetails")); new LatestMessagesCallBack(callback, signers, "getVoter"));
} }
@Override @Override

View File

@ -76,7 +76,7 @@ public interface VoterRegistry {
* @param callBack when the adding voter done callBack.handleResult will be called * @param callBack when the adding voter done callBack.handleResult will be called
* @return list of strings (empty list if the lookup failed) * @return list of strings (empty list if the lookup failed)
*/ */
void getPersonIDDetails(VoterID voterID, RegistryCallBack callBack); void getVoter(VoterID voterID, RegistryCallBack callBack);
/** /**
* Checks if the given voter (by his id) have already voted * Checks if the given voter (by his id) have already voted

View File

@ -58,7 +58,7 @@ public class LatestMessagesCallBack implements FutureCallback<List<BulletinBoard
case "getGroups" : case "getGroups" :
callback.handleResult(GetListOfTags(messages, RegistryTags.GROUP_ID_TAG)); callback.handleResult(GetListOfTags(messages, RegistryTags.GROUP_ID_TAG));
break; break;
case "getPersonIDDetails" : callback.handleResult(lastAddedMessage); case "getVoter" : callback.handleResult(lastAddedMessage);
break; break;
case "hasVoted" : case "hasVoted" :
callback.handleResult(findTagWithPrefix(lastAddedMessage, callback.handleResult(findTagWithPrefix(lastAddedMessage,

View File

@ -1,5 +1,4 @@
import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.FutureCallback;
import junit.framework.TestCase;
import meerkat.Registry; import meerkat.Registry;
import meerkat.bulletinboard.AsyncBulletinBoardClient; import meerkat.bulletinboard.AsyncBulletinBoardClient;
import meerkat.bulletinboard.ThreadedBulletinBoardClient; import meerkat.bulletinboard.ThreadedBulletinBoardClient;
@ -14,6 +13,7 @@ import meerkat.protobuf.VoterRegistry.VoterInfo;
import meerkat.protobuf.Voting; import meerkat.protobuf.Voting;
import meerkat.registry.MessageCollectionUtils; import meerkat.registry.MessageCollectionUtils;
import meerkat.registry.RegistryTags; import meerkat.registry.RegistryTags;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.InputStream; import java.io.InputStream;
@ -25,6 +25,8 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import static meerkat.util.BulletinBoardUtils.findTagWithPrefix; import static meerkat.util.BulletinBoardUtils.findTagWithPrefix;
/** /**
@ -37,7 +39,7 @@ import static meerkat.util.BulletinBoardUtils.findTagWithPrefix;
* NOTE: for most of this tests to pass there should run BulletinBoardServer * NOTE: for most of this tests to pass there should run BulletinBoardServer
* that should be reachable on BULLETIN_BOARD_SERVER_ADDRESS * that should be reachable on BULLETIN_BOARD_SERVER_ADDRESS
*/ */
public class SimpleRegistryTest extends TestCase { public class SimpleRegistryTest /**extends TestCase**/ {
private Collection<DigitalSignature> signers; private Collection<DigitalSignature> signers;
private AsyncBulletinBoardClient bulletinBoardClient; private AsyncBulletinBoardClient bulletinBoardClient;
@ -123,6 +125,7 @@ public class SimpleRegistryTest extends TestCase {
/** /**
* Initialize registry object * Initialize registry object
*/ */
@Before
public void setUp() { public void setUp() {
SetSigner(); SetSigner();
CommunicatorSetup(); CommunicatorSetup();
@ -320,7 +323,7 @@ public class SimpleRegistryTest extends TestCase {
* Test that the personal data outputted about the user is right * Test that the personal data outputted about the user is right
*/ */
@Test @Test
public void testGetPersonalIDDetails() throws InterruptedException { public void testGetVoter() throws InterruptedException {
DummyRegistryCallBackHandler<List<BulletinBoardMessage>> handler = DummyRegistryCallBackHandler<List<BulletinBoardMessage>> handler =
new DummyRegistryCallBackHandler<>(); new DummyRegistryCallBackHandler<>();
@ -336,7 +339,7 @@ public class SimpleRegistryTest extends TestCase {
assertEquals("The callback handler hasn't been called yet", 1, handler.counter ); assertEquals("The callback handler hasn't been called yet", 1, handler.counter );
DummyRegistryCallBackHandler<BulletinBoardMessage> personalHandler = new DummyRegistryCallBackHandler<>(); DummyRegistryCallBackHandler<BulletinBoardMessage> personalHandler = new DummyRegistryCallBackHandler<>();
registry.getPersonIDDetails(VoterID.newBuilder().setId(id).build(), personalHandler); registry.getVoter(VoterID.newBuilder().setId(id).build(), personalHandler);
jobSemaphore.acquire(1); jobSemaphore.acquire(1);
assertEquals("The voter id doesn't match the created on ", assertEquals("The voter id doesn't match the created on ",
@ -345,7 +348,11 @@ public class SimpleRegistryTest extends TestCase {
findTagWithPrefix(personalHandler.data, data) != null); findTagWithPrefix(personalHandler.data, data) != null);
} }
/**
* Tests that the hasVoted method of registry works
* @throws InterruptedException
*/
@Test
public void testHasVoted () throws InterruptedException { public void testHasVoted () throws InterruptedException {
DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>(); DummyRegistryCallBackHandler<Boolean> handler = new DummyRegistryCallBackHandler<>();
String id = generateString(); String id = generateString();
@ -361,6 +368,5 @@ public class SimpleRegistryTest extends TestCase {
jobSemaphore.acquire(1); jobSemaphore.acquire(1);
assertTrue("The voter hasn't voted yet.", personalHandler.data); assertTrue("The voter hasn't voted yet.", personalHandler.data);
} }
} }