package com.fwdekker.randomness;

import java.util.ArrayList;
import java.util.RandomAccess;
import org.junit.Test;

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


/**
 * Unit tests for {@link NamedItem}.
 */
public final class NamedItemTest {
    @Test
    public void testName() {
        final NamedItem<Object> namedItem = new NamedItem<>("OI6d7AkKye", new Object());

        assertThat(namedItem.getName()).isEqualTo("OI6d7AkKye");
    }

    @Test
    public void testItem() {
        final Object item = new Object();

        final NamedItem<Object> namedItem = new NamedItem<>("mrOz7tVmoX", item);

        assertThat(namedItem.getItem()).isEqualTo(item);
    }

    @Test
    public void testToString() {
        final NamedItem<Object> namedItem = new NamedItem<>("2Z6oCfzfli", new Object());

        assertThat(namedItem.toString()).isEqualTo("2Z6oCfzfli");
    }


    @Test
    public void testEqualsSelf() {
        final NamedItem<Object> namedItem = new NamedItem<>("B4md9THj3y", new Object());

        assertThat(namedItem.equals(namedItem)).isTrue();
    }

    @Test
    @SuppressWarnings("PMD.EqualsNull") // Exactly what is being tested here
    public void testEqualsNull() {
        final NamedItem<Object> namedItem = new NamedItem<>("c5pgKxqS41", new Object());

        assertThat(namedItem.equals(null)).isFalse();
    }

    @Test
    public void testEqualsOtherClass() {
        final NamedItem<Object> namedItem = new NamedItem<>("lGdlNMLoyt", new Object());

        assertThat(namedItem.equals(new Object())).isFalse();
    }

    @Test
    public void testEqualsOtherType() {
        final ArrayList realItem = new ArrayList();
        final RandomAccess itemA = realItem;
        final Cloneable itemB = realItem;
        final NamedItem<RandomAccess> namedItemA = new NamedItem<>("znKHUZqExm", itemA);
        final NamedItem<Cloneable> namedItemB = new NamedItem<>("znKHUZqExm", itemB);

        assertThat(namedItemA.equals(namedItemB)).isTrue();
    }

    @Test
    public void testEqualsOtherName() {
        final Object item = new Object();
        final NamedItem<Object> namedItemA = new NamedItem<>("osEjuXELqh", item);
        final NamedItem<Object> namedItemB = new NamedItem<>("BOGVSgfrjF", item);

        assertThat(namedItemA.equals(namedItemB)).isFalse();
    }

    @Test
    public void testEqualsOtherItem() {
        final NamedItem<Object> namedItemA = new NamedItem<>("iMmu1w7Doi", new Object());
        final NamedItem<Object> namedItemB = new NamedItem<>("iMmu1w7Doi", new Object());

        assertThat(namedItemA.equals(namedItemB)).isFalse();
    }

    @Test
    public void testEqualsSame() {
        final Object item = new Object();
        final NamedItem<Object> namedItemA = new NamedItem<>("zIIRUo8lPz", item);
        final NamedItem<Object> namedItemB = new NamedItem<>("zIIRUo8lPz", item);

        assertThat(namedItemA.equals(namedItemB)).isTrue();
    }


    @Test
    public void testHashCodeSelf() {
        final NamedItem<Object> namedItem = new NamedItem<>("2UCKZ9kZ7o", new Object());

        assertThat(namedItem.hashCode()).isEqualTo(namedItem.hashCode());
    }

    @Test
    public void testHashCodeOtherType() {
        final ArrayList realItem = new ArrayList();
        final RandomAccess itemA = realItem;
        final Cloneable itemB = realItem;
        final NamedItem<RandomAccess> namedItemA = new NamedItem<>("vGi5P7o96T", itemA);
        final NamedItem<Cloneable> namedItemB = new NamedItem<>("vGi5P7o96T", itemB);

        assertThat(namedItemA.hashCode()).isEqualTo(namedItemB.hashCode());
    }

    @Test
    public void testHashCodeOtherName() {
        final Object item = new Object();
        final NamedItem<Object> namedItemA = new NamedItem<>("DpMSRx40TF", item);
        final NamedItem<Object> namedItemB = new NamedItem<>("jcnHjZQlOq", item);

        assertThat(namedItemA.hashCode()).isNotEqualTo(namedItemB.hashCode());
    }

    @Test
    public void testHashCodeOtherItem() {
        final NamedItem<Object> namedItemA = new NamedItem<>("iMmu1w7Doi", new Object());
        final NamedItem<Object> namedItemB = new NamedItem<>("iMmu1w7Doi", new Object());

        assertThat(namedItemA.hashCode()).isNotEqualTo(namedItemB.hashCode());
    }

    @Test
    public void testHashCodeSame() {
        final Object item = new Object();
        final NamedItem<Object> namedItemA = new NamedItem<>("hglHcOsYu0", item);
        final NamedItem<Object> namedItemB = new NamedItem<>("hglHcOsYu0", item);

        assertThat(namedItemA.hashCode()).isEqualTo(namedItemB.hashCode());
    }
}

@@ -1675,95 +1675,8 @@
 ();%0A
-        final RandomAccess itemA = realItem;%0A        final Cloneable itemB = realItem;%0A
     
@@ -1752,21 +1752,24 @@
 ZqExm%22, 
-i
+realI
 tem
-A
 );%0A     
@@ -1841,21 +1841,24 @@
 ZqExm%22, 
-i
+realI
 tem
-B
 );%0A%0A    
@@ -3190,95 +3190,8 @@
 ();%0A
-        final RandomAccess itemA = realItem;%0A        final Cloneable itemB = realItem;%0A
     
@@ -3271,13 +3271,16 @@
 T%22, 
-i
+realI
 tem
-A
 );%0A 
@@ -3360,13 +3360,16 @@
 T%22, 
-i
+realI
 tem
-B
 );%0A%0A

Remove unnecessary local variables