SimulatedDevice { public Optional<PlcValue> get(SimulatedField field) { Objects.requireNonNull(field); switch (field.getType()) { case STATE: return Optional.ofNullable(state.get(field)); case RANDOM: return Optional.of(randomValue(field.getDataType())); case STDOUT: return Optional.empty(); } throw new IllegalArgumentException("Unsupported field type: " + field.getType().name()); } SimulatedDevice(String name); Optional<PlcValue> get(SimulatedField field); void set(SimulatedField field, PlcValue value); @Override String toString(); void addCyclicSubscription(Consumer<PlcValue> consumer, PlcSubscriptionHandle handle, SimulatedField plcField, Duration duration); void addChangeOfStateSubscription(Consumer<PlcValue> consumer, PlcSubscriptionHandle handle, SimulatedField plcField); void addEventSubscription(Consumer<PlcValue> consumer, PlcSubscriptionHandle handle, SimulatedField plcField); void removeHandles(Collection<? extends InternalPlcSubscriptionHandle> internalPlcSubscriptionHandles);  }
@Test public void random() { SimulatedDevice device = new SimulatedDevice("foobar"); SimulatedField field = SimulatedField.of("RANDOM/foo:INTEGER"); Optional<PlcValue> value = device.get(field); assertTrue(value.isPresent()); }