package geniusweb.deadline; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.util.Arrays; import java.util.List; import org.junit.Test; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import tudelft.utilities.junit.GeneralTests; public class DeadlineTest extends GeneralTests { private final ObjectMapper jackson = new ObjectMapper(); private final String deadlinestring = "{\"deadlinerounds\":{\"rounds\":100,\"durationms\":999}}"; private final DeadlineRounds deadlineRounds = new DeadlineRounds(100, 999); private final DeadlineRounds deadlineRounds1 = new DeadlineRounds(100, 999); private final DeadlineRounds deadlineRounds2 = new DeadlineRounds(100, 9999); private final String deadlinetimestring = "{\"deadlinetime\":{\"durationms\":2000}}"; private final DeadlineTime deadlineTime = new DeadlineTime(2000); @Override public List> getGeneralTestData() { return Arrays.asList(Arrays.asList(deadlineRounds, deadlineRounds1), Arrays.asList(deadlineRounds2), Arrays.asList(deadlineTime)); } @Override public List getGeneralTestStrings() { return Arrays.asList("DeadlineRounds\\[100,999\\]", "DeadlineRounds\\[100,9999\\]", "DeadlineTime\\[2000\\]"); } @Test public void serializeRoundsTest() throws JsonProcessingException { String text = jackson.writeValueAsString(deadlineRounds); assertEquals(deadlinestring, text); } @Test public void DeserializeRoundsTest() throws JsonParseException, JsonMappingException, IOException { assertEquals(deadlineRounds, jackson.readValue(deadlinestring, Deadline.class)); } @Test public void serializeTimeTest() throws JsonProcessingException { String text = jackson.writeValueAsString(deadlineTime); assertEquals(deadlinetimestring, text); } @Test public void deserializeTimeTest() throws JsonParseException, JsonMappingException, IOException { assertEquals(deadlineTime, jackson.readValue(deadlinetimestring, Deadline.class)); } @SuppressWarnings("unused") @Test(expected = IllegalArgumentException.class) public void testIllegalArg() { new DeadlineRounds(-1, 999); } @SuppressWarnings("unused") @Test(expected = IllegalArgumentException.class) public void testIllegalArg2() { new DeadlineTime(-1); } @Test public void getRounds() { assertEquals((Integer) 11, new DeadlineRounds(11, 20).getRounds()); } }