package geniusweb.party; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import org.junit.Before; import org.junit.Test; import geniusweb.actions.Action; import geniusweb.connection.ConnectionEnd; import geniusweb.inform.Inform; import tudelft.utilities.listener.Listener; public class DefaultPartyTest { private DefaultParty party; @Before public void before() { party = new DefaultParty() { @Override public void notifyChange(Inform data) { // TODO Auto-generated method stub } @Override public String getDescription() { // TODO Auto-generated method stub return null; } @Override public Capabilities getCapabilities() { // TODO Auto-generated method stub return null; } }; } @Test public void smoke() { } @Test public void getReporter() { assertNotNull(party.getReporter()); } @SuppressWarnings("unchecked") @Test public void connect() { ConnectionEnd connection = mock(ConnectionEnd.class); party.connect(connection); verify(connection, times(1)).addListener(any(Listener.class)); assertNotNull(party.getConnection()); } @SuppressWarnings("unchecked") @Test public void disconnect() { ConnectionEnd connection = mock(ConnectionEnd.class); party.connect(connection); party.disconnect(); verify(connection, times(1)).removeListener(any(Listener.class)); assertNull(party.getConnection()); // check second disconnect is ignored party.disconnect(); verify(connection, times(1)).removeListener(any(Listener.class)); assertNull(party.getConnection()); } @SuppressWarnings("unchecked") @Test public void terminate() { ConnectionEnd connection = mock(ConnectionEnd.class); party.connect(connection); party.terminate(); verify(connection, times(1)).removeListener(any(Listener.class)); assertNull(party.getConnection()); // check second terminate is ignored party.terminate(); verify(connection, times(1)).removeListener(any(Listener.class)); assertNull(party.getConnection()); } }