ValueWrapper { public T orElse(T defaultValue) { return valid ? value : defaultValue; } private  ValueWrapper(T value, T expected, boolean valid, String errorMessage); static ValueWrapper<T> of(T value); static ValueWrapper<T> errorWithValidValue(T value, T expected); static ValueWrapper<T> errorWithMessage(String message); static ValueWrapper<T> errorEmptyMessage(); boolean isValid(); T getValue(); T getExpected(); Optional<String> getErrorMessage(); T orElse(T defaultValue); T orElseGet(Supplier<T> defaultSupplier);  }
@Test public void orElse() { assertEquals((Integer) 1, ValueWrapper.of(1).orElse(3)); assertEquals(3, ValueWrapper.errorWithValidValue(null, null).orElse(3)); assertNull(ValueWrapper.of(null).orElse(3)); }