package de.retest.recheck;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.support.membermodification.MemberMatcher.method;

import java.io.File;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import de.retest.recheck.ignore.CompoundFilter;
import de.retest.recheck.ignore.Filter;
import de.retest.recheck.ignore.RecheckIgnoreUtil;
import de.retest.recheck.persistence.FileNamer;

@RunWith( PowerMockRunner.class )
@PrepareForTest( RecheckIgnoreUtil.class )
public class RecheckOptionsTest {

	@Test
	public void should_reuse_file_namer_strategy_for_suite_name() throws Exception {
		mockStatic( RecheckIgnoreUtil.class );
		PowerMockito
				.when( RecheckIgnoreUtil.class,
						method( RecheckIgnoreUtil.class, "loadRecheckSuiteIgnore", File.class ) )
				.withArguments( any() ).thenReturn( null );

		final FileNamerStrategy fileNamerStrategy = mock( FileNamerStrategy.class );

		final FileNamer fileNamer = mock( FileNamer.class );
		when( fileNamerStrategy.createFileNamer( any() ) ).thenReturn( fileNamer );
		when( fileNamerStrategy.getTestClassName() ).thenReturn( "SOME_SPECIAL_VALUE" );

		final RecheckOptions cut = RecheckOptions.builder() //
				.fileNamerStrategy( fileNamerStrategy ) //
				.build();

		assertThat( cut.getSuiteName() ).isEqualTo( fileNamerStrategy.getTestClassName() );
		assertThat( cut.getFileNamerStrategy() ).isEqualTo( fileNamerStrategy );
	}

	@Test
	public void should_use_suite_name_if_set() throws Exception {
		final RecheckOptions cut = RecheckOptions.builder() //
				.suiteName( "bar" ) //
				.build();
		assertThat( cut.getSuiteName() ).isEqualTo( "bar" );
	}

	@Test
	public void should_use_reportUploadEnabled() {
		final RecheckOptions cut = RecheckOptions.builder() //
				.enableReportUpload() //
				.build();
		assertThat( cut.isReportUploadEnabled() ).isEqualTo( true );
	}

	@Test
	public void addFilter_should_add_filter_to_existing() {
		final Filter filter = mock( Filter.class );
		final RecheckOptions cut = RecheckOptions.builder() //
				.addFilter( filter ) //
				.build();
		assertThat( cut.getFilter() ).isInstanceOf( CompoundFilter.class );
		assertThat( ((CompoundFilter) cut.getFilter()).getFilters() ).contains( filter );
	}

	@Test
	public void filter_should_replace_existing() {
		final Filter filter = mock( Filter.class );
		final RecheckOptions cut = RecheckOptions.builder() //
				.setFilter( filter ) //
				.build();
		assertThat( cut.getFilter() ).isEqualTo( filter );
	}
}

@@ -109,276 +109,20 @@
 ito.
-ArgumentMatchers.any;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;%0Aimport static org.powermock.api.mockito.PowerMockito.mockStatic;%0Aimport static org.powermock.api.support.membermodification.MemberMatcher.method;%0A%0Aimport java.io.File
+Mockito.mock
 ;%0A%0Ai
@@ -180,55 +180,8 @@
 th;%0A
-import org.powermock.api.mockito.PowerMockito;%0A
 impo
@@ -438,56 +438,8 @@
 til;
-%0Aimport de.retest.recheck.persistence.FileNamer;
 %0A%0A@R
@@ -643,632 +643,59 @@
 %7B%0A%09%09
-mockStatic( RecheckIgnoreUtil.class );%0A%09%09PowerMockito%0A%09%09%09%09.when( RecheckIgnoreUtil.class,%0A%09%09%09%09%09%09method( RecheckIgnoreUtil.class, %22loadRecheckSuiteIgnore%22, File.class ) )%0A%09%09%09%09.withArguments( any() ).thenReturn( null );%0A%0A%09%09final FileNamerStrategy fileNamerStrategy = mock( FileNamerStrategy.class );%0A%0A%09%09final FileNamer fileNamer = mock( FileNamer.class );%0A%09%09when( fileNamerStrategy.createFileNamer( any() ) ).thenReturn( fileNamer );%0A%09%09when( fileNamerStrategy.getTestClassName() ).thenReturn( %22SOME_SPECIAL_VALUE%22 );%0A%0A%09%09final RecheckOptions cut = RecheckOptions.builder() //%0A%09%09%09%09.fileNamerStrategy( fileNamerStrategy ) //%0A%09%09%09%09
+final RecheckOptions cut = RecheckOptions.builder()
 .bui
@@ -700,17 +700,16 @@
 uild();%0A
-%0A
 %09%09assert
@@ -750,119 +750,28 @@
 To( 
-fileNamerStrategy.getTestClassName() );%0A%09%09assertThat( cut.getFileNamerStrategy() ).isEqualTo( fileNamerStrategy
+getClass().getName()
  );%0A

Simplify test