FuelTypeValue extends AbstractSensorCommandValue { public Optional<FuelType> getType() { return FuelType.valueOf(getIntValue()); } FuelTypeValue(CommandResult commandResult); Optional<FuelType> getType();  }
@Test public void getTypeShouldSelectProperEnumType() throws Exception { boolean fuelTypesAreEqual = true; for (FuelType expectedFuelType : FuelType.values()) { when(commandResultMock.getByteNumber(0)).thenReturn(expectedFuelType.getTypeNumber()); Optional<FuelType> fuelTypeOptional = sut.getType(); FuelType fuelType = fuelTypeOptional.get(); fuelTypesAreEqual &= fuelType.equals(expectedFuelType); } assertThat(fuelTypesAreEqual).isTrue(); }
@Test public void getTypeShouldReturnAbsentForUnknownFuelTypeByte() throws Exception { int maxFuelTypeNumber = getMaxFuelTypeNumber(); int unknownFuelTypeNumber = maxFuelTypeNumber + 1; when(commandResultMock.getByteNumber(0)).thenReturn(unknownFuelTypeNumber); Optional<FuelType> fuelTypeOptional = sut.getType(); assertThat(fuelTypeOptional.isPresent()).isFalse(); }