@Test
public void shouldFindServerGivenAValidNetworkResponse() throws Exception {

  final ServerProtocol mockServerProtocol = getMockServerProtocol();
  final ServerEntity mockServerEntity = getMockServerEntity();
  CommandMessage mockCommandMessage = mock(CommandMessage.class);
  when(mockProtocolMessageComposer.composeGetServerInfoCommand()).thenReturn(mockCommandMessage);
  when(mockMessageJsonMapper.transformMessage(mockCommandMessage)).thenReturn("whatever");
  Message mockMessage = mock(Message.class);
  when(mockMessage.isSuccess()).thenReturn(true);
  when(mockMessage.isServer()).thenReturn(true);
  when(mockMessage.getServer()).thenReturn(mockServerProtocol);
  when(mockMessageJsonMapper.transformMessage(anyString())).thenReturn(mockMessage);
  when(mockServerMessageValidator.isValid(mockMessage)).thenReturn(true);
  when(mockServerMessageValidator.cast(mockMessage)).thenReturn(mockServerProtocol);
  when(mockServerProtocolMapper.transform(mockServerProtocol)).thenReturn(mockServerEntity);
  Observable<ServerEntity> serverEntityObservable = serverSearchManager.searchServer();
  ServerEntity serverEntity = serverEntityObservable.blockingFirst();
  assertThat(serverEntity, notNullValue());
  assertThat(serverEntity.worldName(), is("Za warudo"));
  verify(mockNetworkConnectionlessTransmitter, times(1)).setBroadcast(true);
  verify(mockProtocolMessageComposer, atLeastOnce()).composeGetServerInfoCommand();
  verify(mockMessageJsonMapper, atLeastOnce()).transformMessage(any(CommandMessage.class));
  verify(mockNetworkConnectionlessTransmitter, atLeastOnce()).send(any(NetworkPacket.class));
  verify(mockBroadcastAddressProvider, only()).getBroadcastAddresses();
  verify(mockNetworkConnectionlessTransmitter, atLeastOnce()).setTimeout(
      mockServerSearchSettings.getTimeout());
  verify(mockNetworkConnectionlessTransmitter, atLeastOnce()).receive(any(NetworkPacket.class));
  verify(mockMessageJsonMapper).transformMessage(anyString());
}