### Question:
ExposedThingProperty extends ThingProperty<T> { public CompletableFuture<T> write(T value) { if (state.getWriteHandler() != null) { log.debug("'{}' calls registered writeHandler for Property '{}'", thing.getId(), name); try { return state.getWriteHandler().apply(value).whenComplete((customValue, e) -> { log.debug("'{}' write handler for Property '{}' sets custom value '{}'", thing.getId(), name, customValue); if (!Objects.equals(state.getValue(), customValue)) { state.setValue(customValue); state.getSubject().onNext(Optional.ofNullable(customValue)); } }); } catch (Exception e) { return failedFuture(e); } } else { if (!Objects.equals(state.getValue(), value)) { log.debug("'{}' sets Property '{}' to internal value '{}'", thing.getId(), name, value); state.setValue(value); state.getSubject().onNext(Optional.ofNullable(value)); } return completedFuture(null); } } @SuppressWarnings("squid:S107")  ExposedThingProperty(String name,
                                ExposedThing thing,
                                PropertyState<T> state,
                                String objectType,
                                String description,
                                Map<String, String> descriptions,
                                String type,
                                boolean observable,
                                boolean readOnly,
                                boolean writeOnly,
                                Map<String, Map<String, Object>> uriVariables,
                                Map<String, Object> optionalProperties);  ExposedThingProperty(String name, ThingProperty<T> property, ExposedThing thing); CompletableFuture<T> read(); CompletableFuture<T> write(T value); Observable<Optional<T>> observer(); PropertyState<T> getState(); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString();  }### Answer:
@Test public void writeWithoutHandlerShouldSetStateValueAndInformSubject() { when(state.getSubject()).thenReturn(subject); exposedProperty = new ExposedThingProperty<>(name, thing, state, objectType, description, descriptions, type, observable, readOnly, writeOnly, uriVariables, optionalProperties); exposedProperty.write(1337); verify(state).setValue(1337); verify(subject).onNext(Optional.of(1337)); }
@Test public void writeWithHandlerShouldCallHandlerAndInformSubject() { when(writeHandler.apply(any())).thenReturn(completedFuture(1337)); when(state.getWriteHandler()).thenReturn(writeHandler); when(state.getSubject()).thenReturn(subject); exposedProperty = new ExposedThingProperty<>(name, thing, state, objectType, description, descriptions, type, observable, readOnly, writeOnly, uriVariables, optionalProperties); exposedProperty.write(1337); verify(writeHandler).apply(1337); verify(subject).onNext(Optional.of(1337)); }