package de.retest.recheck.persistence;

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

import java.io.File;
import java.nio.file.Path;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.TempDirectory;
import org.junitpioneer.jupiter.TempDirectory.TempDir;

import de.retest.recheck.report.SuiteReplayResult;

@ExtendWith( TempDirectory.class )
class RecheckTestReportUtilTest {

	File file;
	File fileMissingFolders;

	@BeforeEach
	void setUp( @TempDir final Path temp ) {
		file = temp.resolve( "test.report" ).toFile();
		fileMissingFolders = temp.resolve( "retest" + File.separator + "recheck" + File.separator + "test.report" ).toFile();
	}

	@Test
	void persist_should_create_report_if_no_errors() {
		final SuiteReplayResult replayResult = mock( SuiteReplayResult.class );
		when( replayResult.getDifferencesCount() ).thenReturn( 0 );

		RecheckTestReportUtil.persist( replayResult, file );
		assertThat( file.exists() ).isTrue();
	}

	@Test
	void persist_should_create_report_if_errors() {
		final SuiteReplayResult replayResult = mock( SuiteReplayResult.class );
		when( replayResult.getDifferencesCount() ).thenReturn( 1 );

		RecheckTestReportUtil.persist( replayResult, file );
		assertThat( file.exists() ).isTrue();
	}

	@Test
	void persist_should_create_missing_folders() {
		final SuiteReplayResult replayResult = mock( SuiteReplayResult.class );
		when( replayResult.getDifferencesCount() ).thenReturn( 0 );

		RecheckTestReportUtil.persist( replayResult, fileMissingFolders );
	}
}

@@ -583,24 +583,36 @@
 ile 
-file;%0A%09File file
+testReport;%0A%09File testReport
 Miss
@@ -681,20 +681,26 @@
 p ) %7B%0A%09%09
-file
+testReport
  = temp.
@@ -736,20 +736,26 @@
 le();%0A%09%09
-file
+testReport
 MissingF
@@ -782,65 +782,23 @@
 e( %22
-retest%22 + File.separator + %22recheck%22 + File.separator + %22
+missing/folder/
 test
@@ -868,19 +868,30 @@
 ort_
-if_no_error
+when_there_are_no_diff
 s() 
@@ -1068,36 +1068,42 @@
 ( replayResult, 
-file
+testReport
  );%0A%09%09assertThat
@@ -1096,36 +1096,42 @@
 ;%0A%09%09assertThat( 
-file
+testReport
 .exists() ).isTr
@@ -1186,16 +1186,27 @@
 ort_
-if_error
+when_there_are_diff
 s() 
@@ -1391,20 +1391,26 @@
 Result, 
-file
+testReport
  );%0A%09%09as
@@ -1419,20 +1419,26 @@
 rtThat( 
-file
+testReport
 .exists(
@@ -1694,20 +1694,26 @@
 Result, 
-file
+testReport
 MissingF

Refactor test