package de.retest.recheck.ignore;

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

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import de.retest.recheck.review.ignore.AttributeFilter;
import de.retest.recheck.review.ignore.MatcherFilter;
import de.retest.recheck.review.ignore.matcher.ElementRetestIdMatcher;
import de.retest.recheck.ui.descriptors.Element;
import de.retest.recheck.ui.diff.AttributeDifference;

class AllMatchFilterTest {

	Filter cut;

	@BeforeEach
	void setUp() {
		final Element element = mock( Element.class );
		when( element.getRetestId() ).thenReturn( "abc" );

		cut = new AllMatchFilter( new MatcherFilter( new ElementRetestIdMatcher( element ) ),
				new AttributeFilter( "123" ) );
	}

	@Test
	void matches_should_always_return_false() {
		final Element element = mock( Element.class );
		when( element.getRetestId() ).thenReturn( "abc" );

		assertThat( cut.matches( element ) ).isFalse();
	}

	@Test
	void matches_should_return_true() {
		final Element element = mock( Element.class );
		when( element.getRetestId() ).thenReturn( "abc" );

		final AttributeDifference difference = mock( AttributeDifference.class );
		when( difference.getKey() ).thenReturn( "123" );

		assertThat( cut.matches( element, difference ) ).isTrue();
	}

	@Test
	void matches_should_return_false_when_key_does_not_match() {
		final Element element = mock( Element.class );
		when( element.getRetestId() ).thenReturn( "abc" );

		final AttributeDifference difference = mock( AttributeDifference.class );
		when( difference.getKey() ).thenReturn( "234" );

		assertThat( cut.matches( element, difference ) ).isFalse();
	}

	@Test
	void matches_should_return_false_when_element_does_not_match() {
		final Element element = mock( Element.class );
		when( element.getRetestId() ).thenReturn( "ABC" );

		final AttributeDifference difference = mock( AttributeDifference.class );
		when( difference.getKey() ).thenReturn( "123" );

		assertThat( cut.matches( element, difference ) ).isFalse();
	}

	@Test
	void should_match_with_attribute_key_when_attribute_is_same() {
		final Element element = mock( Element.class );
		when( element.getRetestId() ).thenReturn( "abc" );
		final String attributeKey = "123";

		assertThat( cut.matches( element, attributeKey ) ).isTrue();
	}

	@Test
	void should_not_match_with_attribute_key_when_attribute_is_different() {
		final Element element = mock( Element.class );
		when( element.getRetestId() ).thenReturn( "abc" );
		final String attributeKey = "234";

		assertThat( cut.matches( element, attributeKey ) ).isFalse();
	}

	@Test
	void no_filters_given_should_throw_exception() {
		assertThatThrownBy( () -> new AllMatchFilter() ).isInstanceOf( IllegalArgumentException.class );
	}

}

@@ -914,29 +914,31 @@
 oid 
+not_
 match
-es_should_always
+ing_all_should
 _ret
@@ -1118,34 +1118,39 @@
 Test%0A%09void match
-es
+ing_all
 _should_return_t
@@ -1462,32 +1462,24 @@
 @Test%0A%09void 
-matches_
 should_retur
@@ -1828,16 +1828,8 @@
 oid 
-matches_
 shou
@@ -2669,24 +2669,24 @@
 y = %22234%22;%0A%0A
-
 %09%09assertThat
@@ -2733,32 +2733,595 @@
 .isFalse();%0A%09%7D%0A%0A
+%09@Test%0A%09void should_match_if_parent_matches() %7B%0A%09%09final Element parent = mock( Element.class );%0A%09%09when( parent.getRetestId() ).thenReturn( %22abc%22 );%0A%09%09final Element element = mock( Element.class );%0A%09%09when( element.getParent() ).thenReturn( parent );%0A%09%09when( element.getRetestId() ).thenReturn( %22some other%22 );%0A%0A%09%09final AttributeDifference difference = mock( AttributeDifference.class );%0A%09%09when( difference.getKey() ).thenReturn( %22123%22 );%0A%0A%09%09assertThat( cut.matches( parent, difference ) ).isTrue();%0A%09%09assertThat( cut.matches( element, difference ) ).isTrue();%0A%09%7D%0A%0A
 %09@Test%0A%09void no_

Improve names and add one more test