package de.retest.recheck;

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

import org.junit.jupiter.api.Test;

import de.retest.recheck.ignore.CompoundFilter;
import de.retest.recheck.ignore.Filter;

class RecheckOptionsTest {

	@Test
	void should_reuse_file_namer_strategy_for_suite_name() throws Exception {
		final FileNamerStrategy fileNamerStrategy = spy( new MavenConformFileNamerStrategy() );
		when( fileNamerStrategy.getTestClassName() ).thenReturn( "foo" );
		final RecheckOptions cut = RecheckOptions.builder() //
				.fileNamerStrategy( fileNamerStrategy ) //
				.build();
		assertThat( cut.getSuiteName() ).isEqualTo( "foo" );
	}

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

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

	@Test
	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 );
		final CompoundFilter compoundFilter = (CompoundFilter) cut.getFilter();
		// added filter + global ignore + suite ignore
		assertThat( compoundFilter.getFilters() ).hasSize( 3 );
		assertThat( ( (CompoundFilter) compoundFilter.getFilters().get( 0 ) ).getFilters() ).contains( filter );
	}

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

@@ -83,48 +83,8 @@
 at;%0A
-import static org.mockito.Mockito.mock;%0A
 impo
@@ -159,16 +159,40 @@
 .when;%0A%0A
+import java.util.List;%0A%0A
 import o
@@ -1249,54 +1249,8 @@
 ) %7B%0A
-%09%09final Filter filter = mock( Filter.class );%0A
 %09%09fi
@@ -1310,30 +1310,49 @@
 %09%09%09%09.add
-Filter( 
+Ignore( %22style-attributes.
 filter
+%22
  ) //%0A%09%09
@@ -1441,16 +1441,45 @@
 %09%09final 
+List%3CFilter%3E filters =%0A%09%09%09%09((
 Compound
@@ -1484,18 +1484,21 @@
 ndFilter
- c
+) ((C
 ompoundF
@@ -1502,19 +1502,19 @@
 ndFilter
- = 
+) (
 (Compoun
@@ -1541,220 +1541,177 @@
 er()
-;%0A%09%09// added filter + global ignore + suite ignore%0A%09%09assertThat( compoundFilter.getFilters() ).hasSize( 3 );%0A%09%09assertThat( ( (CompoundFilter) compoundFilter.getF
+).getFilters().get( 0 ))%0A%09%09%09%09%09%09.getFilters().get( 0 )).getFilters();%0A%09%09assertThat( f
 ilters
-()
 .get( 0
- )
  ).
-getFilters() ).contains( filter
+toString() ).isEqualTo( %22# Style attributes filter file for recheck.%22
  );%0A
@@ -1769,54 +1769,8 @@
 ) %7B%0A
-%09%09final Filter filter = mock( Filter.class );%0A
 %09%09fi
@@ -1834,22 +1834,41 @@
 .set
-Filter( 
+Ignore( %22style-attributes.
 filter
+%22
  ) /
@@ -1921,23 +1921,189 @@
 ).is
-EqualTo( filter
+InstanceOf( CompoundFilter.class );%0A%09%09assertThat( ((CompoundFilter) cut.getFilter()).getFilters().get( 0 ).toString() )%0A%09%09%09%09.isEqualTo( %22# Style attributes filter file for recheck.%22
  );%0A

Fix failing test