### Question:
SportTypeViewModel { public SportType getSportType() { final SportType sportType = new SportType(id); sportType.setName(name.getValue().trim()); sportType.setRecordDistance(recordDistance.getValue()); sportType.setSpeedMode(speedMode.getValue().getSpeedMode()); sportType.setIcon(StringUtils.getTrimmedTextOrNull(icon.getValue())); sportType.setColor(color.getValue()); sportSubtypes.forEach(sportSubType -> sportType.getSportSubTypeList().set(sportSubType)); equipments.forEach(equipment -> sportType.getEquipmentList().set(equipment)); return sportType; } SportTypeViewModel(final SportType sportType); SportType getSportType(); final int id; final StringProperty name; final BooleanProperty recordDistance; final ObjectProperty<SpeedModeItem> speedMode; final StringProperty icon; final ObjectProperty<Color> color; final IdObjectList<SportSubType> sportSubtypes; final IdObjectList<Equipment> equipments; }### Answer:
@Test public void testGetSportTypeUnmodified() { SportTypeViewModel viewModel = new SportTypeViewModel(sportType); SportType unmodifiedSportType = viewModel.getSportType(); assertEquals(sportType.getId(), unmodifiedSportType.getId()); assertEquals(sportType.getName(), unmodifiedSportType.getName()); assertEquals(sportType.isRecordDistance(), unmodifiedSportType.isRecordDistance()); assertEquals(sportType.getSpeedMode(), unmodifiedSportType.getSpeedMode()); assertEquals(sportType.getColor(), unmodifiedSportType.getColor()); assertEquals(sportType.getIcon(), unmodifiedSportType.getIcon()); assertEquals(2, unmodifiedSportType.getSportSubTypeList().size()); assertEquals(200, unmodifiedSportType.getSportSubTypeList().getAt(0).getId()); assertEquals(201, unmodifiedSportType.getSportSubTypeList().getAt(1).getId()); assertEquals(2, unmodifiedSportType.getEquipmentList().size()); assertEquals(300, unmodifiedSportType.getEquipmentList().getAt(0).getId()); assertEquals(301, unmodifiedSportType.getEquipmentList().getAt(1).getId()); }
@Test public void testGetSportTypeModified() { SportTypeViewModel viewModel = new SportTypeViewModel(sportType); viewModel.name.set(" Bar Foo "); viewModel.recordDistance.set(true); viewModel.speedMode.set(SpeedModeItem.SPEED.SPEED); viewModel.color.set(Color.color(1.0d, 0.5d, 0d)); viewModel.sportSubtypes.removeByID(200); viewModel.equipments.set(new Equipment(302)); SportType modifiedSportType = viewModel.getSportType(); assertEquals("Bar Foo", modifiedSportType.getName()); assertTrue(modifiedSportType.isRecordDistance()); assertEquals(SpeedMode.SPEED, modifiedSportType.getSpeedMode()); assertEquals(Color.color(1.0d, 0.5d, 0d), modifiedSportType.getColor()); assertEquals(1, modifiedSportType.getSportSubTypeList().size()); assertEquals(201, modifiedSportType.getSportSubTypeList().getAt(0).getId()); assertEquals(3, modifiedSportType.getEquipmentList().size()); assertEquals(300, modifiedSportType.getEquipmentList().getAt(0).getId()); assertEquals(301, modifiedSportType.getEquipmentList().getAt(1).getId()); assertEquals(302, modifiedSportType.getEquipmentList().getAt(2).getId()); }