package de.retest.recheck.printer;

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

import java.io.Serializable;
import java.util.Objects;

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

import de.retest.recheck.ui.DefaultValueFinder;
import de.retest.recheck.ui.descriptors.IdentifyingAttributes;
import de.retest.recheck.ui.diff.AttributeDifference;

class AttributeDifferencePrinterTest {

	AttributeDifferencePrinter cut;

	@BeforeEach
	void setUp() {
		final IdentifyingAttributes attributes = mock( IdentifyingAttributes.class );
		cut = new AttributeDifferencePrinter( attributes, new PrinterFinder() );
	}

	@Test
	void toString_should_identify_actual_default() {
		final AttributeDifference d1 = new AttributeDifference( "a", "b", "a" );

		final String string = cut.toString( d1 );

		assertThat( string ).contains( "actual=\"(default or absent)\"" );
	}

	@Test
	void toString_should_not_identify_actual_default() {
		final AttributeDifference d1 = new AttributeDifference( "a", "b", "b" );

		final String string = cut.toString( d1 );

		assertThat( string ).doesNotContain( "actual=\"(default or absent)\"" );
	}

	@Test
	void to_String_should_expect_expected_default_when_null() {
		final AttributeDifference difference = new AttributeDifference( "a", null, "b" );

		final String string = cut.toString( difference );

		assertThat( string ).contains( "expected=\"(default or absent)\"" );
	}

	@Test
	void to_String_should_take_expected_priority_when_actual_default() {
		final AttributeDifference difference = new AttributeDifference( "a", null, "a" );

		final String string = cut.toString( difference );

		assertThat( string ).contains( "expected=\"(default or absent)\"" );
	}

	class PrinterFinder implements DefaultValueFinder {

		@Override
		public boolean isDefaultValue( final IdentifyingAttributes attributes, final String key,
				final Serializable value ) {
			return Objects.equals( "a", value );
		}
	}
}

@@ -425,16 +425,79 @@
 ference;
+%0Aimport de.retest.recheck.ui.diff.ElementIdentificationWarning;
 %0A%0Aclass 
@@ -1835,16 +1835,1744 @@
  );%0A%09%7D%0A%0A
+%09@Test%0A%09void to_String_should_identify_actual_default_and_attach_warning() %7B%0A%09%09final AttributeDifference difference = new AttributeDifference( %22a%22, %22b%22, %22a%22 );%0A%09%09final ElementIdentificationWarning warning =%0A%09%09%09%09new ElementIdentificationWarning( %22TestClassIT.java%22, 31, %22id%22, %22de.example.web.TestClassIT%22 );%0A%09%09difference.addElementIdentificationWarning( warning );%0A%0A%09%09final String string = cut.toString( difference );%0A%0A%09%09assertThat( string ).contains( %22actual=%5C%22(default or absent)%5C%22%22 ).contains( %22breaks=%5C%22TestClassIT.java:31%5C%22%22 );%0A%09%7D%0A%0A%09@Test%0A%09void to_String_should_expect_expected_default_when_null_and_attach_warning() %7B%0A%09%09final AttributeDifference difference = new AttributeDifference( %22a%22, null, %22a%22 );%0A%09%09final ElementIdentificationWarning warning =%0A%09%09%09%09new ElementIdentificationWarning( %22FooIT.java%22, 2, %22id%22, %22de.example.web.FooIT%22 );%0A%09%09difference.addElementIdentificationWarning( warning );%0A%0A%09%09final String string = cut.toString( difference );%0A%0A%09%09assertThat( string ).contains( %22expected=%5C%22(default or absent)%5C%22%22 ).contains( %22breaks=%5C%22FooIT.java:2%5C%22%22 );%0A%09%7D%0A%0A%09@Test%0A%09void to_String_should_attach_amount_of_warnings() %7B%0A%09%09final AttributeDifference difference = new AttributeDifference( %22a%22, %22a%22, %22b%22 );%0A%09%09final ElementIdentificationWarning warning1 =%0A%09%09%09%09new ElementIdentificationWarning( %22FooIT.java%22, 2, %22id%22, %22de.example.web.FooIT%22 );%0A%09%09final ElementIdentificationWarning warning2 =%0A%09%09%09%09new ElementIdentificationWarning( %22BarIT.java%22, 3, %22id%22, %22de.example.web.BarIT%22 );%0A%09%09difference.addElementIdentificationWarning( warning1 );%0A%09%09difference.addElementIdentificationWarning( warning2 );%0A%0A%09%09final String string = cut.toString( difference );%0A%0A%09%09assertThat( string ).contains( %22breaks=%5C%22FooIT.java:2, BarIT.java:3%5C%22%22 );%0A%09%7D%0A%0A
 %09class P

Add tests