package org.parsemylegacy.definition;

import org.junit.Test;
import org.parsemylegacy.examples.Person;
import org.parsemylegacy.utils.TrimDirection;

import java.lang.reflect.Field;

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

public class ColumnDefinitionTest {

    @Test
    public void should_calculate_immutable_hashcode() throws Exception {
        Field personFirstNameField = Person.class.getDeclaredField("firstname");
        ColumnDefinition columnDefinition = new ColumnDefinition(personFirstNameField, 1, 25, true, ' ', TrimDirection.RIGHT);
        assertThat(columnDefinition.hashCode()).isEqualTo(-1005108454);
    }

    @Test
    public void should_compare_with_null_object() throws Exception {
        Field personFirstNameField = Person.class.getDeclaredField("firstname");
        ColumnDefinition columnDefinition1 = new ColumnDefinition(personFirstNameField, 1, 25, true, ' ', TrimDirection.RIGHT);
        assertThat(columnDefinition1.equals(null)).isFalse();
    }

    @Test
    public void should_compare_with_object_of_another_type() throws Exception {
        Field personFirstNameField = Person.class.getDeclaredField("firstname");
        ColumnDefinition columnDefinition1 = new ColumnDefinition(personFirstNameField, 1, 25, true, ' ', TrimDirection.RIGHT);
        assertThat(columnDefinition1.equals(new Object())).isFalse();
    }

    @Test
    public void should_compare_same_objects() throws Exception {
        Field personFirstNameField = Person.class.getDeclaredField("firstname");
        ColumnDefinition columnDefinition1 = new ColumnDefinition(personFirstNameField, 1, 25, true, ' ', TrimDirection.RIGHT);
        assertThat(columnDefinition1.equals(columnDefinition1)).isTrue();
    }

    @Test
    public void should_compare_equal_objects() throws Exception {
        Field personFirstNameField = Person.class.getDeclaredField("firstname");
        ColumnDefinition columnDefinition1 = new ColumnDefinition(personFirstNameField, 1, 25, true, ' ', TrimDirection.RIGHT);
        ColumnDefinition columnDefinition2 = new ColumnDefinition(personFirstNameField, 1, 25, true, ' ', TrimDirection.RIGHT);
        assertThat(columnDefinition1.equals(columnDefinition2)).isTrue();
    }

    @Test
    public void should_compare_different_objects() throws Exception {
        Field personFirstNameField = Person.class.getDeclaredField("firstname");
        ColumnDefinition columnDefinition1 = new ColumnDefinition(personFirstNameField, 1, 25, true, ' ', TrimDirection.RIGHT);
        ColumnDefinition columnDefinition2 = new ColumnDefinition(personFirstNameField, 99, 111, true, ' ', TrimDirection.RIGHT);
        assertThat(columnDefinition1.equals(columnDefinition2)).isFalse();
    }
}

@@ -320,18 +320,8 @@
 ate_
-immutable_
 hash
@@ -338,32 +338,32 @@
 ows Exception %7B%0A
+
         Field pe
@@ -468,16 +468,145 @@
 finition
+1 = new ColumnDefinition(personFirstNameField, 1, 25, true, ' ', TrimDirection.RIGHT);%0A        ColumnDefinition columnDefinition2
  = new C
@@ -718,16 +718,17 @@
 finition
+1
 .hashCod
@@ -746,19 +746,36 @@
 lTo(
--1005108454
+columnDefinition2.hashCode()
 );%0A 

Fix hashcode test for ColumnDefinition