/** * Creates a new {@link Input} instance that is defined in case if {@code value} is not-null * and undefined otherwise. * * @param value to be wrapped * @return a new {@link Input} instance */ public static <V> Input<V> optional(@Nullable V value) { if (value == null) { return absent(); } else { return fromNullable(value); } }
@Test public void testInputEqualsOnNullValue() { Input<String> stringInput = Input.fromNullable(null); Input<String> anotherStringInput = Input.fromNullable(null); assertEquals(stringInput, anotherStringInput); }
@Test public void testInputEqualsOnNotNullValue() { String value = "Hello world!"; Input<String> stringInput = Input.fromNullable(value); Input<String> anotherStringInput = Input.fromNullable(value); assertEquals(stringInput, anotherStringInput); }
@Test public void testInputNotEqualsOnDifferentValues() { String value = "Hello world!"; String value2 = "Bye world!"; Input<String> stringInput = Input.fromNullable(value); Input<String> anotherStringInput = Input.fromNullable(value2); assertNotEquals(stringInput, anotherStringInput); }
@Test public void testInputEqualsOnObjectsWithNullValue() { TestObject object = new TestObject(null); Input<TestObject> aInput = Input.fromNullable(object); Input<TestObject> anotherInput = Input.fromNullable(object); assertEquals(aInput, anotherInput); }
@Test public void testInputEqualsOnNotNullObjects() { TestObject object = new TestObject("Hello world!"); Input<TestObject> aInput = Input.fromNullable(object); Input<TestObject> anotherInput = Input.fromNullable(object); assertEquals(aInput, anotherInput); }
@Test public void testInputNotEqualsWhenAnObjectIsNull() { TestObject object = new TestObject(null); Input<TestObject> aInput = Input.fromNullable(object); Input<TestObject> anotherInput = Input.fromNullable(null); assertNotEquals(aInput, anotherInput); }
@Test public void testInputEqualsOnEqualObjectsWithDifferentReferences() { TestObject object1 = new TestObject("Hello world!"); TestObject object2 = new TestObject("Hello world!"); Input<TestObject> input1 = Input.fromNullable(object1); Input<TestObject> input2 = Input.fromNullable(object2); assertEquals(input1, input2); }
@Test public void testInputNotEqualsOnDifferentObjects() { TestObject object = new TestObject("Hello world!"); TestObject anotherObject = new TestObject("Bye world!"); Input<TestObject> aInput = Input.fromNullable(object); Input<TestObject> anotherInput = Input.fromNullable(anotherObject); assertNotEquals(aInput, anotherInput); }