package de.retest.recheck.util;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Optional;
import java.util.function.Supplier;

import org.junit.jupiter.api.Test;

class OptionalUtilTest {

	@Test
	void stream_should_contain_value_if_present() {
		final Object obj = new Object();
		final Optional<Object> present = Optional.of( obj );
		assertThat( OptionalUtil.stream( present ) ).containsExactly( obj );
	}

	@Test
	void stream_should_be_empty_if_absent() throws Exception {
		final Optional<Object> absent = Optional.empty();
		assertThat( OptionalUtil.stream( absent ) ).isEmpty();
	}

	@Test
	void or_should_return_given_optional_if_present() throws Exception {
		final Optional<Object> opt = Optional.of( new Object() );
		final Supplier<Optional<Object>> supplier = () -> Optional.empty();
		assertThat( OptionalUtil.or​( opt, supplier ) ).isEqualTo( opt );
	}

	@Test
	void or_should_return_use_supplier_if_absent() throws Exception {
		final Optional<Object> absent = Optional.empty();
		final Optional<Object> present = Optional.of( new Object() );
		final Supplier<Optional<Object>> supplier = () -> present;
		assertThat( OptionalUtil.or​( absent, supplier ) ).isEqualTo( present );
	}

}

@@ -116,44 +116,49 @@
 al;%0A
+%0A
 import 
-java.util.function.Supplier;%0A
+org.junit.jupiter.api.BeforeEach;
 %0Aimp
@@ -221,152 +221,268 @@
 %7B%0A%0A%09
-@Test%0A%09void stream_should_contain_value_if_present() %7B%0A%09%09final 
+Object value;%0A%09Optional%3CObject%3E present;%0A%09Optional%3C
 Object
- obj = new Object();%0A%09%09final Optional%3CObject%3E present = Optional.of( obj );
+%3E absent;%0A%0A%09@BeforeEach%0A%09void setUp() throws Exception %7B%0A%09%09value = new Object();%0A%09%09present = Optional.of( value );%0A%09%09absent = Optional.empty();%0A%09%7D%0A%0A%09@Test%0A%09void stream_should_contain_value_if_present() %7B
 %0A%09%09a
@@ -546,11 +546,13 @@
 ly( 
-obj
+value
  );%0A
@@ -626,60 +626,8 @@
 n %7B%0A
-%09%09final Optional%3CObject%3E absent = Optional.empty();%0A
 %09%09as
@@ -764,138 +764,8 @@
 n %7B%0A
-%09%09final Optional%3CObject%3E opt = Optional.of( new Object() );%0A%09%09final Supplier%3COptional%3CObject%3E%3E supplier = () -%3E Optional.empty();%0A
 %09%09as
@@ -796,21 +796,29 @@
 r%E2%80%8B( 
-opt, supplier
+present, () -%3E absent
  ) )
@@ -829,18 +829,22 @@
 qualTo( 
-o
 p
+resen
 t );%0A%09%7D%0A
@@ -924,231 +924,59 @@
 %7B%0A%09%09
-final Optional%3CObject%3E absent = Optional.empty();%0A%09%09final Optional%3CObject%3E present = Optional.of( new Object() );%0A%09%09final Supplier%3COptional%3CObject%3E%3E supplier = () -%3E present;%0A%09%09assertThat( OptionalUtil.or%E2%80%8B( absent, supplier
+assertThat( OptionalUtil.or%E2%80%8B( absent, () -%3E present
  ) )

Refactor test