package de.retest.recheck.report;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

import org.junit.jupiter.api.Test;

import de.retest.recheck.NoGoldenMasterActionReplayResult;
import static org.mockito.Mockito.when;

import java.util.stream.Collectors;
import java.util.stream.Stream;

import de.retest.recheck.ui.diff.LeafDifference;

class TestReplayResultTest {

	@Test
	void hasNoGoldenMaster_should_return_false_if_no_specific_result_is_present() {
		final TestReplayResult cut = new TestReplayResult( "foo", 42 );
		cut.addAction( mock( ActionReplayResult.class ) );

		assertThat( cut.hasNoGoldenMaster() ).isFalse();
	}

	@Test
	void hasNoGoldenMaster_should_return_false_if_not_all_gm() {
		final TestReplayResult cut = new TestReplayResult( "foo", 42 );
		cut.addAction( mock( NoGoldenMasterActionReplayResult.class ) );
		cut.addAction( mock( ActionReplayResult.class ) );

		assertThat( cut.hasNoGoldenMaster() ).isFalse();
	}

	@Test
	void hasNoGoldenMaster_should_return_true_only_if_all_are_not_present() {
		final TestReplayResult cut = new TestReplayResult( "foo", 42 );
		cut.addAction( mock( NoGoldenMasterActionReplayResult.class ) );
		cut.addAction( mock( NoGoldenMasterActionReplayResult.class ) );

		assertThat( cut.hasNoGoldenMaster() ).isTrue();
	}

	@Test
	void getDifferences_should_retrieve_all_child_differences() {
		final TestReplayResult cut = new TestReplayResult( "foo", 5 );
		cut.addAction( action() );
		cut.addAction( action() );
		cut.addAction( action() );

		assertThat( cut.getDifferences() ).hasSize( 15 );
	}

	private ActionReplayResult action() {
		final ActionReplayResult replayResult = mock( ActionReplayResult.class );
		when( replayResult.getDifferences() ).thenReturn(
				Stream.generate( () -> mock( LeafDifference.class ) ).limit( 5 ).collect( Collectors.toSet() ) );
		return replayResult;
	}
}

@@ -124,108 +124,66 @@
 ito.
-mock;%0A%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport de.retest.recheck.NoGoldenMasterActionReplayResult
+RETURNS_DEEP_STUBS;%0Aimport static org.mockito.Mockito.mock
 ;%0Aim
@@ -290,16 +290,111 @@
 tream;%0A%0A
+import org.junit.jupiter.api.Test;%0A%0Aimport de.retest.recheck.NoGoldenMasterActionReplayResult;%0A
 import d
@@ -1655,16 +1655,677 @@
  );%0A%09%7D%0A%0A
+%09@Test%0A%09void isEmpty_should_return_true_if_no_differences() throws Exception %7B%0A%09%09final ActionReplayResult action = mock( ActionReplayResult.class );%0A%0A%09%09final TestReplayResult cut = new TestReplayResult( %22foo%22, 1 );%0A%09%09cut.addAction( action );%0A%0A%09%09assertThat( cut.isEmpty() ).isTrue();%0A%09%7D%0A%0A%09@Test%0A%09void isEmpty_should_return_false_if_differences() throws Exception %7B%0A%09%09final ActionReplayResult action = mock( ActionReplayResult.class, RETURNS_DEEP_STUBS );%0A%09%09when( action.getAllElementDifferences().size() ).thenReturn( 1 );%0A%0A%09%09final TestReplayResult cut = new TestReplayResult( %22foo%22, 2 );%0A%09%09cut.addAction( action );%0A%0A%09%09assertThat( cut.isEmpty() ).isFalse();%0A%09%7D%0A%0A
 %09private

Add test for wrong behavior