package de.retest.recheck.ui.diff;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import org.junit.jupiter.api.Test;

import de.retest.recheck.ui.diff.AttributeDifference;

class AttributeDifferenceTest {

	@Test
	void apply_changes_to_null_attribute_yields_NullPointerException() {
		final AttributeDifference cut = new AttributeDifference();
		assertThatThrownBy( () -> cut.applyChangeTo( null ) ) //
				.isInstanceOf( NullPointerException.class ) //
				.hasMessage( "Cannot apply change to an attribute that is null." );
	}

	@Test
	void equals_should_be_false_for_null() {
		final AttributeDifference cut = new AttributeDifference();
		assertThat( cut.equals( null ) ).isFalse();
	}

	@Test
	void equals_should_be_false_for_other_types() {
		final AttributeDifference cut = new AttributeDifference();
		assertThat( cut.equals( new Object() ) ).isFalse();
	}

	@Test
	void equals_should_be_true_if_same_object() {
		final AttributeDifference cut = new AttributeDifference();
		assertThat( cut.equals( cut ) ).isTrue();
	}

	@Test
	void equals_should_be_true_if_same_properties() {
		final String key = "key";
		final String expected = "foo";
		final String actual = "bar";
		final AttributeDifference cut0 = new AttributeDifference( key, expected, actual );
		final AttributeDifference cut1 = new AttributeDifference( key, expected, actual );
		assertThat( cut0.equals( cut1 ) ).isTrue();
	}

	@Test
	void equals_should_be_false_if_not_same_properties() {
		final String key = "key";
		final String expected = "foo";
		final String actual = "bar";
		final AttributeDifference cut0 = new AttributeDifference( key, expected, actual );
		final AttributeDifference cut1 = new AttributeDifference( key, expected, "baz" );
		assertThat( cut0.equals( cut1 ) ).isFalse();
	}
}

@@ -153,24 +153,30 @@
 rownBy;%0A
-%0A
 import 
+static 
 org.juni
@@ -193,111 +193,278 @@
 api.
-Test;%0A%0Aimport de.retest.recheck.ui.diff.AttributeDifference;%0A%0Aclass AttributeDifferenceTest %7B%0A%0A%09@Test%0A%09
+Assertions.assertEquals;%0A%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.contrib.java.lang.system.SystemOutRule;%0A%0Apublic class AttributeDifferenceTest %7B%0A%0A%09@Rule%0A%09public final SystemOutRule systemOutRule = new SystemOutRule().enableLog();%0A%0A%09@Test%0A%09public 
 void
@@ -525,16 +525,33 @@
 eption()
+ throws Exception
  %7B%0A%09%09fin
@@ -804,647 +804,270 @@
 st%0A%09
-void equals_should_be_false_for_null() %7B%0A%09%09final AttributeDifference cut = new AttributeDifference();%0A%09%09assertThat( cut.equals( null ) ).isFalse();%0A%09%7D%0A%0A%09@Test%0A%09void equals_should_be_false_for_other_types() %7B%0A%09%09final AttributeDifference cut = new AttributeDifference();%0A%09%09assertThat( cut.equals( new Object() ) ).isFalse();%0A%09%7D%0A%0A%09@Test%0A%09void equals_should_be_true_if_same_object() %7B%0A%09%09final AttributeDifference cut = new AttributeDifference();%0A%09%09assertThat( cut.equals( cut ) ).isTrue();%0A%09%7D%0A%0A%09@Test%0A%09void equals_should_be_true_if_same_properties() %7B%0A%09%09final String key = %22key%22;%0A%09%09final String expected = %22foo%22;%0A%09%09final String actual = %22bar%22;
+public void compare_to_same_object_is_zero() throws Exception %7B%0A%09%09final AttributeDifference cut = new AttributeDifference();%0A%09%09assertEquals( 0, cut.compareTo( cut ) );%0A%09%7D%0A%0A%09@Test%0A%09public void warn_if_attributes_dont_match_logs_correct_string() throws Exception %7B
 %0A%09%09f
@@ -1086,33 +1086,32 @@
 teDifference cut
-0
  = new Attribute
@@ -1126,536 +1126,348 @@
 ce( 
-key, expected, actual );%0A%09%09final AttributeDifference cut1 = new AttributeDifference( key, expected, actual );%0A%09%09assertThat( cut0.equals( cut1 ) ).isTrue();%0A%09%7D%0A%0A%09@Test%0A%09void equals_should_be_false_if_not_same_properties() %7B%0A%09%09final String key = %22key%22;%0A%09%09final String expected = %22foo%22;%0A%09%09final String actual = %22bar%22;%0A%09%09final AttributeDifference cut0 = new AttributeDifference( key, expected, actual );%0A%09%09final AttributeDifference cut1 = new AttributeDifference( key,
+null, %22something%22, null );%0A%09%09cut.warnIfAttributesDontMatch( %22somethingElse%22 );%0A%0A%09%09final String expected = %22Mismatch for attribute 'null': value from ExecSuite 'somethingElse', %22%0A%09%09%09%09+ %22value from TestResult 'something'. This could be due to a change of the
  ex
-p
 ec
-ted, %22baz%22 );%0A%09%09assertThat( cut0.equals( cut1 ) ).isFalse(
+suite in between.%22;%0A%0A%09%09assertThat( systemOutRule.getLog() ).contains( expected 
 );%0A%09

Delete tests for equals and add test for compareTo