### Question:
PartyListener implements Listener { @EventHandler public void connect(ServerConnectEvent event) { taskFactory.newAsyncTask(() -> playerMessaging.distribute( partyService .getInvitedMembers(event.getPlayer().getName()), s -> new PartyTeleport(s, event.getPlayer().getName()) )).execute(); }  @EventHandler void connect(ServerConnectEvent event); @EventHandler void disconnect(PlayerDisconnectEvent playerDisconnectEvent);  }### Answer:
@Test public void whenConnectThenAllJoined() { TaskFactory taskFactory = mock(TaskFactory.class); when(taskFactory.newAsyncTask(any())).thenAnswer((Answer<Task>) invocation -> () -> { Runnable r = invocation.getArgument(0); r.run(); }); PlayerMessaging playerMessaging = mock(PlayerMessaging.class); PartyService partyService = mock(PartyService.class); when(partyService.getInvitedMembers(eq("owner"))).thenReturn( new TreeSet<>(Arrays.asList("1", "2", "3")) ); ServerConnectEvent event = mock(ServerConnectEvent.class); when(event.getPlayer()).thenAnswer(invocation -> { ProxiedPlayer proxiedPlayer = mock(ProxiedPlayer.class); when(proxiedPlayer.getName()).thenReturn("owner"); return proxiedPlayer; }); PartyListener listener = new PartyListener(partyService, playerMessaging, taskFactory); listener.connect(event); verify(playerMessaging).distribute( eq(new TreeSet<>(Arrays.asList("1", "2", "3"))), any() ); }