package de.retest.recheck.review.ignore;

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

import java.awt.Rectangle;

import org.junit.jupiter.api.Test;

import de.retest.recheck.ignore.Filter;
import de.retest.recheck.ui.descriptors.Element;
import de.retest.recheck.ui.diff.AttributeDifference;

class PixelDiffFilterTest {

	double pixelDiff = 5.0;
	Filter cut = new PixelDiffFilter( false, pixelDiff );

	@Test
	void should_filter_diff_when_pixel_diff_is_not_exceeded() throws Exception {
		final Rectangle expected = new Rectangle( 0, 0, 10, 10 );
		final Rectangle actual = new Rectangle( 1, -1, 15, 5 );
		final AttributeDifference diff = new AttributeDifference( "outline", expected, actual );

		assertThat( cut.matches( mock( Element.class ), diff ) ).isTrue();
	}

	@Test
	void should_not_filter_diff_when_pixel_diff_is_exceeded() throws Exception {
		final Rectangle expected = new Rectangle( 0, 0, 10, 10 );
		final Rectangle actual = new Rectangle( 1, -1, 15, 5 );
		final AttributeDifference diff = new AttributeDifference( "outline", expected, actual );

		final Filter cut = new PixelDiffFilter( false, 0.0 );

		assertThat( cut.matches( mock( Element.class ), diff ) ).isFalse();
	}

	@Test
	void should_handle_pixel_strings_with_integers_and_floats() throws Exception {
		final String expected = "50px";
		final String actual = "45.3px";
		final AttributeDifference diff = new AttributeDifference( "foo", expected, actual );

		assertThat( cut.matches( mock( Element.class ), diff ) ).isTrue();
	}

	@Test
	void should_handle_pixel_strings_with_negative_integers_and_floats() throws Exception {
		final String expected = "-50px";
		final String actual = "-45.3px";
		final AttributeDifference diff = new AttributeDifference( "foo", expected, actual );

		assertThat( cut.matches( mock( Element.class ), diff ) ).isTrue();
	}

	@Test
	void should_handle_pixel_strings_with_different_decimal_separators() throws Exception {
		final String expected = "50.0px";
		final String actual = "45,3px";
		final AttributeDifference diff = new AttributeDifference( "foo", expected, actual );

		assertThat( cut.matches( mock( Element.class ), diff ) ).isTrue();
	}

	@Test
	void should_skip_nulls() throws Exception {
		final String expected = null;
		final String actual = null;
		final AttributeDifference diff = new AttributeDifference( "foo", expected, actual );

		assertThat( cut.matches( mock( Element.class ), diff ) ).isFalse();
	}

	@Test
	void should_skip_non_pixel_strings() throws Exception {
		final String expected = "bar";
		final String actual = "baz";
		final AttributeDifference diff = new AttributeDifference( "foo", expected, actual );

		assertThat( cut.matches( mock( Element.class ), diff ) ).isFalse();
	}

	@Test
	void specifiedAsDouble_flag_should_control_toString() throws Exception {
		assertThat( new PixelDiffFilter( false, 0.0 ) ).hasToString( "pixel-diff=0" );
		assertThat( new PixelDiffFilter( true, 0.0 ) ).hasToString( "pixel-diff=0.0" );
	}

}

@@ -3030,10 +3030,294 @@
  );%0A%09%7D%0A%0A
+%09@Test%0A%09void style_attribute_should_return_false() %7B%0A%09%09final String expected = %2218px%22;%0A%09%09final String actual = %22189px%22;%0A%09%09final AttributeDifference diff = new AttributeDifference( %22style%22, expected, actual );%0A%0A%09%09assertThat( cut.matches( mock( Element.class ), diff ) ).isFalse();%0A%09%7D%0A%0A
 %7D%0A

Add test