ServerModelDataMapper { public ServerModel transform(Server server) { if (server == null) { throw new IllegalArgumentException("Cannot transform a null Server object."); } return ServerModel.builder() .ssid(server.ssid()) .ip(server.ip()) .hostname(server.hostname()) .os(server.os()) .version(server.version()) .seed(server.seed()) .worldName(server.worldName()) .playerName(server.playerName()) .encodedWorldImage(server.encodedWorldImage()) .build(); } @Inject  ServerModelDataMapper(); ServerModel transform(Server server); Collection<ServerModel> transform(Collection<Server> serversCollection);  }
@Test public void shouldNotReturnNullWorldModelWhenMappingValidWorld() throws Exception { Server server = getFakeServer(); ServerModel serverModel = serverModelDataMapper.transform(server); assertNotNull(serverModel); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionWhenMappingNullWorld() throws Exception { Server server = null; serverModelDataMapper.transform(server); }
@Test public void shouldReturnWorldModelInstanceWhenMappingWorld() throws Exception { Server server = getFakeServer(); ServerModel serverModel = serverModelDataMapper.transform(server); assertThat(serverModel, is(instanceOf(ServerModel.class))); }
@Test public void shouldTransformProperlyAllFieldsWhenMappingWorld() throws Exception { Server server = getFakeServer(); ServerModel serverModel = serverModelDataMapper.transform(server); assertThat(FAKE_SSID, is(serverModel.ssid())); assertThat(FAKE_IP, is(serverModel.ip())); assertThat(FAKE_VERSION, is(serverModel.version())); assertThat(FAKE_SEED, is(serverModel.seed())); assertThat(FAKE_WORLD_NAME, is(serverModel.worldName())); assertThat(FAKE_PLAYER_NAME, is(serverModel.playerName())); assertThat(FAKE_ENCODED_WORLD_IMAGE, is(serverModel.encodedWorldImage())); }
@Test public void shouldReturnEmptyWorldModelCollectionWhenMappingEmptyWorldCollection() throws Exception { Collection<ServerModel> serverModels = serverModelDataMapper.transform(Collections.emptyList()); assertThat(serverModels, is(Collections.emptyList())); assertTrue(serverModels.isEmpty()); }
@Test public void shouldReturnTheSameAmountOfElementsWhenMappingWorldCollection() throws Exception { ArrayList<Server> servers = new ArrayList<>(); servers.add(getFakeServer()); servers.add(getFakeServer()); servers.add(getFakeServer()); Collection<ServerModel> serverModels = serverModelDataMapper.transform(servers); assertNotNull(serverModels); assertThat(serverModels.size(), is(3)); }
@Test public void shouldReturnWorldModelInstanceCollectionWhenMappingWorldCollection() throws Exception { ArrayList<Server> servers = new ArrayList<>(); servers.add(getFakeServer()); servers.add(getFakeServer()); servers.add(getFakeServer()); ArrayList<ServerModel> serverModels = (ArrayList<ServerModel>) serverModelDataMapper.transform(servers); assertThat(serverModels.get(0), is(instanceOf(ServerModel.class))); assertThat(serverModels.get(1), is(instanceOf(ServerModel.class))); assertThat(serverModels.get(2), is(instanceOf(ServerModel.class))); }