package geniusweb.inform; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.Arrays; import java.util.Collections; import java.util.List; import org.junit.Before; import org.junit.Test; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import geniusweb.actions.PartyId; import geniusweb.issuevalue.Bid; import geniusweb.issuevalue.DiscreteValue; import geniusweb.issuevalue.Value; import tudelft.utilities.junit.GeneralTests; public class FinishedTest extends GeneralTests { private final ObjectMapper jackson = new ObjectMapper(); private static final PartyId id = new PartyId("party1"); private static final PartyId id2 = new PartyId("party2"); private final static Value VALUE1 = new DiscreteValue("value1"); private static Bid bid = new Bid( Collections.singletonMap("issue1", VALUE1)); private final String finishedstring = "{\"Finished\":{\"agreements\":{\"party1\":{\"issuevalues\":{\"issue1\":\"value1\"}}}}}"; private final static Agreements agrees1 = new Agreements( Collections.singletonMap(id, bid)); private final static Agreements agrees2 = new Agreements( Collections.singletonMap(id2, bid)); private final static Finished finished1 = new Finished(agrees1); private final static Finished finished1a = new Finished(agrees1); private final static Finished finished2 = new Finished(agrees2); @Override public List> getGeneralTestData() { return Arrays.asList(Arrays.asList(finished1, finished1a), Arrays.asList(finished2)); } @Override public List getGeneralTestStrings() { return Arrays.asList("Finished.*party1.*Bid.*", "Finished.*party2.*Bid.*"); } @Before public void before() { } @Test public void serializeAcceptTest() throws JsonProcessingException { System.out.println(jackson.writeValueAsString(finished1)); assertEquals(finishedstring, jackson.writeValueAsString(finished1)); } @Test public void deserializeAcceptTest() throws IOException { Inform act = jackson.readValue(finishedstring, Inform.class); assertEquals(finished1, act); } @Test(expected = NullPointerException.class) public void testNull() { new Finished(null); } }