Index: protocol/src/test/java/geniusweb/protocol/session/shaop/SHAOPStateTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/session/shaop/SHAOPStateTest.java	(revision 18)
+++ protocol/src/test/java/geniusweb/protocol/session/shaop/SHAOPStateTest.java	(revision 18)
@@ -0,0 +1,316 @@
+package geniusweb.protocol.session.shaop;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import geniusweb.actions.Accept;
+import geniusweb.actions.Action;
+import geniusweb.actions.EndNegotiation;
+import geniusweb.actions.Offer;
+import geniusweb.actions.PartyId;
+import geniusweb.issuevalue.Bid;
+import geniusweb.progress.Progress;
+import geniusweb.progress.ProgressRounds;
+import geniusweb.progress.ProgressTime;
+import geniusweb.protocol.ProtocolException;
+import geniusweb.protocol.partyconnection.ProtocolToPartyConn;
+import geniusweb.protocol.partyconnection.ProtocolToPartyConnections;
+import geniusweb.protocol.session.TeamOfPartiesAndProfiles;
+import tudelft.utilities.junit.GeneralTests;
+
+public class SHAOPStateTest extends GeneralTests<SHAOPState> {
+	private final long NOW = 1000;
+
+	private PartyId party1 = new PartyId("party1");
+	private PartyId party2 = new PartyId("party2");
+	private PartyId party3 = new PartyId("party3");
+	private PartyId party4 = new PartyId("party4");
+	private List<Action> actions = new LinkedList<>();
+	private Action action = mock(Action.class);
+	private List<Action> actions2 = Arrays.asList(action);
+
+	private ProtocolToPartyConn party1conn = mock(ProtocolToPartyConn.class);
+	private ProtocolToPartyConn party2conn = mock(ProtocolToPartyConn.class);
+	private ProtocolToPartyConn party3conn = mock(ProtocolToPartyConn.class);
+	private ProtocolToPartyConn party4conn = mock(ProtocolToPartyConn.class);
+
+	private ProtocolToPartyConnections connections = new ProtocolToPartyConnections(
+			Arrays.asList(party1conn, party2conn));
+	private ProtocolToPartyConnections connections2 = new ProtocolToPartyConnections(
+			Arrays.asList(party1conn, party3conn));
+	private ProtocolToPartyConnections connections3 = new ProtocolToPartyConnections(
+			Arrays.asList(party1conn, party2conn, party3conn));
+	private ProtocolToPartyConnections connections4 = new ProtocolToPartyConnections(
+			Arrays.asList(party1conn, party2conn, party3conn, party4conn));
+
+	private Progress progresstime = mock(ProgressTime.class);
+	private ProgressRounds progressrounds = mock(ProgressRounds.class);
+	private ProgressRounds progressrounds1 = mock(ProgressRounds.class);
+	private SHAOPSettings settings = mock(SHAOPSettings.class);
+	private SHAOPState state1, state1a, state2, state3, state4;
+
+	private Bid bid1 = mock(Bid.class);
+	private Bid otherbid = mock(Bid.class);
+	private Accept accept1 = new Accept(party1, bid1);
+	private Accept accept2 = new Accept(party2, bid1);
+	private Accept acceptother = new Accept(party2, otherbid);
+	private Offer offer1 = new Offer(party1, bid1);
+	private EndNegotiation endNegotiation1 = new EndNegotiation(party1);
+	private Map<PartyId, Integer> partynrs = new HashMap<>();
+
+	private TeamOfPartiesAndProfiles team1 = mock(
+			TeamOfPartiesAndProfiles.class);
+	private TeamOfPartiesAndProfiles team2 = mock(
+			TeamOfPartiesAndProfiles.class);
+
+	@Before
+	public void before() {
+		when(party1conn.getParty()).thenReturn(party1);
+		when(party2conn.getParty()).thenReturn(party2);
+		when(party3conn.getParty()).thenReturn(party3);
+		when(party1conn.toString()).thenReturn("conn1");
+		when(party2conn.toString()).thenReturn("conn2");
+		when(party3conn.toString()).thenReturn("conn3");
+		when(party4conn.toString()).thenReturn("conn4");
+		when(action.toString()).thenReturn("act1");
+		when(settings.toString()).thenReturn("settings");
+		when(progressrounds.toString()).thenReturn("progressrounds");
+		when(progresstime.toString()).thenReturn("progresstime");
+
+		when(progressrounds.getTerminationTime())
+				.thenReturn(new Date(System.currentTimeMillis() + 3600000l));
+		when(progressrounds1.getTerminationTime())
+				.thenReturn(new Date(System.currentTimeMillis() + 3600000l));
+		when(progressrounds.advance()).thenReturn(progressrounds1);
+
+		partynrs.put(party1, 0);
+		partynrs.put(party2, 1);
+		partynrs.put(party3, 2);
+		partynrs.put(party4, 3);
+		Map<PartyId, Double> totalspent = new HashMap<>();
+
+		state1 = new SHAOPState(actions, connections, progresstime, settings,
+				null, 0, partynrs, totalspent);
+		state1a = new SHAOPState(actions, connections, progresstime, settings,
+				null, 0, partynrs, totalspent);
+		state2 = new SHAOPState(actions2, connections, progresstime, settings,
+				null, 0, partynrs, totalspent);
+		state3 = new SHAOPState(actions, connections, progressrounds, settings,
+				null, 0, partynrs, totalspent);
+		state4 = new SHAOPState(actions, connections, progresstime, settings,
+				null, 1, partynrs, totalspent);
+
+		when(settings.getTeams()).thenReturn(Arrays.asList(team1, team2));
+
+	}
+
+	@Override
+	public List<List<SHAOPState>> getGeneralTestData() {
+		return Arrays.asList(Arrays.asList(state1, state1a),
+				Arrays.asList(state2), Arrays.asList(state3),
+				Arrays.asList(state4));
+	}
+
+	@Override
+	public List<String> getGeneralTestStrings() {
+		return Arrays.asList(
+				"SHAOPState.*\\[\\].*ConnectionWithParties.*conn1.*conn2.*progresstime.*settings.*",
+				"SHAOPState.*\\[act1\\].*ConnectionWithParties.*conn1.*conn2.*progresstime.*settings.*",
+				"SHAOPState.*\\[\\].*ConnectionWithParties.*conn1.*conn2.*progressrounds.*settings.*",
+				"SHAOPState.*\\[\\].*ConnectionWithParties.*conn1.*conn2.*progresstime.*settings.*");
+	}
+
+	@Test
+	public void constructWith0Connection() {
+		new SHAOPState(actions, new ProtocolToPartyConnections(Arrays.asList()),
+				progresstime, settings, null, 0, null, null);
+	}
+
+	@Test
+	public void constructWithNullConnection() {
+		SHAOPState state = new SHAOPState(actions, null, progresstime, settings,
+				null, 0, null, null);
+		assertEquals(0, state.getConnections().size());
+	}
+
+	@Test
+	public void testCurrentActor() {
+		assertEquals(party1, state1.getCurrentTeam());
+	}
+
+	@Test
+	public void testNextActor2() {
+		ProtocolToPartyConnections conns = new ProtocolToPartyConnections(
+				Arrays.asList(party2conn, party3conn));
+		SHAOPState state = new SHAOPState(actions, conns, progresstime,
+				settings, null, 0, partynrs, null);
+		assertEquals(party2, state.getCurrentTeam());
+	}
+
+	@Test
+	public void testNextActorAfterAction() {
+		List<Action> actions = Arrays.asList(action);
+		SHAOPState state = new SHAOPState(actions, connections, progresstime,
+				settings, null, 0, null, null);
+		assertEquals(party1, state.getCurrentTeam());
+	}
+
+	@Test
+	public void isFinalTest() {
+		assertFalse(state1.isFinal(NOW));
+		SHAOPState state = new SHAOPState(actions, connections, progresstime,
+				settings, mock(ProtocolException.class), 0, null, null);
+		assertTrue(state.isFinal(NOW));
+	}
+
+	@Test
+	public void withExceptionTest() {
+		SHAOPState finalstate1 = state1.with(mock(ProtocolException.class));
+		assertTrue(finalstate1.isFinal(NOW));
+		SHAOPState finalstate2 = finalstate1
+				.with(mock(ProtocolException.class));
+		assertTrue(finalstate2.isFinal(NOW));
+	}
+
+	@Test
+	public void isOfferAgreementTest1() {
+		List<Action> actions = Arrays.asList(offer1);
+		SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
+				settings, null, 0, null, null);
+		assertNull(state.getAgreement());
+	}
+
+	@Test
+	public void isOfferAcceptAgreementTest() {
+		List<Action> actions = Arrays.asList(offer1, accept2);
+		SHAOPState state = new SHAOPState(actions, connections4, progressrounds,
+				settings, null, 0, null, null);
+		assertNotNull(state.getAgreement());
+		assertTrue(state.isFinal(NOW));
+	}
+
+	@Test
+	public void isOfferAcceptOfferAgreementTest() {
+		List<Action> actions = Arrays.asList(offer1, accept1, offer1);
+		SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
+				settings, null, 0, null, null);
+		assertNull(state.getAgreement());
+	}
+
+	@Test
+	public void isOfferAcceptAcceptotherAgreementTest() {
+		List<Action> actions = Arrays.asList(offer1, accept1, acceptother);
+		SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
+				settings, null, 0, null, null);
+		assertEquals(null, state.getAgreement());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withWrongActionTest() {
+		// wrong because action has actor null which does not match party1
+		SHAOPState state = state1.with(party1, action);
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void withActionTest() {
+		when(action.getActor()).thenReturn(party1);
+		state1.with(party1, action);
+	}
+
+	@Test
+	public void withConnectionTest() {
+		SHAOPState state = state1.with(party3conn);
+		assertEquals(3, state.getConnections().size());
+	}
+
+	@Test
+	public void isEndNegotiationFinalTest() {
+		List<Action> actions = Arrays.asList(endNegotiation1);
+		SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
+				settings, null, 0, null, null);
+		assertEquals(null, state.getAgreement());
+		assertEquals(null, state.getError());
+		assertTrue(state.isFinal(NOW));
+
+	}
+
+	@Test
+	public void isProtocolErrorFinal() {
+		SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
+				settings, new ProtocolException("test error", "test"), 0, null,
+				null);
+		assertTrue(state.isFinal(NOW));
+		assertNotNull(state.getError());
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void RefuseImmediateAccept() {
+		Accept nullaccept = new Accept(party1, null);
+		SHAOPState state = state1.with(party1, nullaccept);
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void RefuseNotMyTurn() {
+		List<Action> actions = Arrays.asList(offer1);
+		SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
+				settings, null, 1, partynrs, null);
+
+		state.with(party1, offer1);
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void RefuseNullAccept() {
+		List<Action> actions = Arrays.asList(offer1);
+		SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
+				settings, null, 0, partynrs, null);
+
+		Accept nullaccept = new Accept(party2, null);
+		state = state.with(party2, nullaccept);
+		assertTrue(state.isFinal(NOW));
+	}
+
+	@Test(expected = IllegalArgumentException.class)
+	public void RefuseNullAction() {
+		List<Action> actions = Arrays.asList(offer1);
+		SHAOPState state = new SHAOPState(actions, connections3, progressrounds,
+				settings, null, 0, null, null);
+
+		state = state.with(party2, null);
+	}
+
+	@Test
+	public void testRoundNumberAfterActions() {
+
+		SHAOPState state = new SHAOPState(actions, connections4,
+				new ProgressRounds(10, 0, null), settings, null, 0, partynrs,
+				null);
+
+		assertEquals((Double) 0d,
+				state.getProgress().get(System.currentTimeMillis()));
+		Offer act1 = new Offer(party1, bid1);
+		state = state.with(party1, act1);
+		assertEquals((Double) 0d,
+				state.getProgress().get(System.currentTimeMillis()));
+		Offer act2 = new Offer(party3, bid1);
+		state = state.with(party3, act2);
+		assertEquals((Double) 0.1d,
+				state.getProgress().get(System.currentTimeMillis()));
+
+	}
+
+}
Index: protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java
===================================================================
--- protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java	(revision 14)
+++ protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java	(revision 18)
@@ -32,7 +32,7 @@
 	private final ObjectMapper jackson = new ObjectMapper();
 
-	private final String serialized = "{\"AllPermutationsSettings\":{\"teams\":[{\"Team\":[{\"partyref\":\"party1\",\"parameters\":{}}]},{\"Team\":[{\"partyref\":\"party2\",\"parameters\":{}}]}],\"profileslists\":[{\"ProfileList\":[\"profile1\"]},{\"ProfileList\":[\"profile2\"]},{\"ProfileList\":[\"profile3\"]}],\"reuseTeams\":false,\"teamsPerSession\":2,\"sessionsettings\":{\"SAOPSettings\":{\"participants\":[],\"deadline\":{\"deadlinetime\":{\"durationms\":10000}}}}}}";
+	private final String serialized = "{\"AllPermutationsSettings\":{\"teams\":[{\"Team\":[{\"partyref\":\"party1\",\"parameters\":{}}]},{\"Team\":[{\"partyref\":\"party2\",\"parameters\":{}}]}],\"profileslists\":[{\"ProfileList\":[\"profile1\"]},{\"ProfileList\":[\"profile2\"]},{\"ProfileList\":[\"profile3\"]}],\"reuseTeams\":false,\"teamsPerSession\":2,\"sessionsettings\":{\"SAOPSettings\":{\"participants\":[],\"deadline\":{\"deadlinetime\":{\"durationms\":10000}}}},\"numberTournaments\":1}}";
 	private AllPermutationsSettings settings, settings1a, settings2, settings3,
-			settings4;
+			settings4, settings5;
 
 	// use directly because there is some hard coding currently.
@@ -76,19 +76,22 @@
 
 		settings = new AllPermutationsSettings(parties, profiles, false, 2,
-				saopsettings);
+				saopsettings, 1);
 
 		settings1a = new AllPermutationsSettings(parties, profiles, false, 2,
-				saopsettings);
+				saopsettings, 1);
 
 		settings2 = new AllPermutationsSettings(Arrays.asList(partywithparams1,
 				partywithparams2, partywithparams3), profiles, false, 2,
-				saopsettings);
+				saopsettings, 1);
 
 		settings3 = new AllPermutationsSettings(parties, profiles, true, 2,
-				saopsettings);
+				saopsettings, 1);
 
 		settings4 = new AllPermutationsSettings(parties,
 				Arrays.asList(profiles1, profiles2, profiles3, profiles1),
-				false, 2, saopsettings);
+				false, 2, saopsettings, 1);
+
+		settings5 = new AllPermutationsSettings(parties, profiles, false, 2,
+				saopsettings, 2);
 
 	}
@@ -98,5 +101,5 @@
 		return Arrays.asList(Arrays.asList(settings, settings1a),
 				Arrays.asList(settings2), Arrays.asList(settings3),
-				Arrays.asList(settings4));
+				Arrays.asList(settings4), Arrays.asList(settings5));
 	}
 
@@ -104,8 +107,9 @@
 	public List<String> getGeneralTestStrings() {
 		return Arrays.asList(
-				"AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*",
-				"AllPermutationsSettings.*party1.*party2.*party3.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*",
-				"AllPermutationsSettings.*party1.*party2.*,true,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*",
-				"AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*profile1.*,2,SAOPSettings.*");
+				"AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*1.*",
+				"AllPermutationsSettings.*party1.*party2.*party3.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*1.*",
+				"AllPermutationsSettings.*party1.*party2.*,true,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*1.*",
+				"AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*profile1.*,2,SAOPSettings.*1.*",
+				"AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*2.*");
 	}
 
@@ -137,5 +141,5 @@
 		new AllPermutationsSettings(null,
 				Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
-				2, saopsettings);
+				2, saopsettings, 1);
 
 	}
@@ -145,5 +149,5 @@
 		new AllPermutationsSettings(Collections.emptyList(),
 				Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
-				2, saopsettings);
+				2, saopsettings, 1);
 
 	}
@@ -151,5 +155,5 @@
 	@Test(expected = IllegalArgumentException.class)
 	public void testNullProfiles() {
-		new AllPermutationsSettings(parties, null, true, 2, saopsettings);
+		new AllPermutationsSettings(parties, null, true, 2, saopsettings, 1);
 
 	}
@@ -159,5 +163,5 @@
 		new AllPermutationsSettings(parties,
 				Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
-				4, saopsettings);
+				4, saopsettings, 1);
 
 	}
@@ -167,5 +171,5 @@
 		new AllPermutationsSettings(parties,
 				Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
-				4, null);
+				4, null, 1);
 
 	}
@@ -175,5 +179,5 @@
 		new AllPermutationsSettings(parties,
 				Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
-				1, saopsettings);
+				1, saopsettings, 1);
 
 	}
