### Question:
WeightViewModel { public Weight getWeight() { final Weight weight = new Weight(id); weight.setDateTime(LocalDateTime.of(date.get(), time.get())); weight.setValue(value.get()); weight.setComment(StringUtils.getTrimmedTextOrNull(comment.getValue())); if (unitSystem == UnitSystem.ENGLISH) { weight.setValue((float) ConvertUtils.convertLbs2Kilogram(weight.getValue())); } return weight; } WeightViewModel(final Weight weight, final UnitSystem unitSystem); Weight getWeight(); final ObjectProperty<LocalDate> date; final ObjectProperty<LocalTime> time; final FloatProperty value; final StringProperty comment; }### Answer:
@Test public void testGetWeightWithMetricUnits() { WeightViewModel viewModel = new WeightViewModel(weight, UnitSystem.METRIC); assertEquals(weight.getValue(), viewModel.value.get(), 0.0001f); Weight unmodifiedWeight = viewModel.getWeight(); assertEquals(weight.getId(), unmodifiedWeight.getId()); assertEquals(weight.getDateTime(), unmodifiedWeight.getDateTime()); assertEquals(weight.getValue(), unmodifiedWeight.getValue(), 0.0001f); assertEquals(weight.getComment(), unmodifiedWeight.getComment()); viewModel.time.set(LocalTime.of(14, 45)); viewModel.value.set(67.5f); viewModel.comment.set(" Bar Foo "); Weight modifiedWeight = viewModel.getWeight(); assertEquals(LocalDateTime.of(2014, 10, 20, 14, 45, 0), modifiedWeight.getDateTime()); assertEquals(67.5f, modifiedWeight.getValue(), 0.0001f); assertEquals("Bar Foo", modifiedWeight.getComment()); }
@Test public void testGetWeightWithEnglishUnits() { WeightViewModel viewModel = new WeightViewModel(weight, UnitSystem.ENGLISH); assertEquals(144.8422, viewModel.value.get(), 0.0001f); Weight unmodifiedWeight = viewModel.getWeight(); assertEquals(weight.getValue(), unmodifiedWeight.getValue(), 0.0001f); }