package addresses;

import static org.junit.Assert.*;

import org.junit.Test;

public class AddressTest {

 

    @Test

    public void test() {

        fail("Not yet implemented");

    }

}

 

 

 

 

 

package addresses;

import static org.junit.Assert.*;

import org.junit.Test;

 

public class AddressTest {

    @Test

    public void testEquals() {

        Address a1 = new Address(1, "Main Road",

            "Vicksburg", 57332, "USA");

        Address a2 = new Address(1, "Main Road",

            "Vicksburg", 57332, "USA");

        Address a3 = new Address(2, "Main Road",

             "Vicksburg", 57332, "USA");

        assertEquals(a1, a2);

        assertFalse(a1.equals(a3));

        assertFalse(a1.equals("Hello World"));

    }

}

 

 

 

 

 

@Test

public void testHashKey() {

    Address a1 = new Address(1, "Main Road",

        "Vicksburg", 57332, "USA");

    Address a2 = new Address(1, "Main Road",

        "Vicksburg", 57332, "USA");

    Address a3 = new Address(2, "Main Road",

        "Vicksburg", 57332, "USA");

    assertEquals(a1.hashCode(), a2.hashCode());

    assertFalse(a1.hashCode() == a3.hashCode());

}

     

@Test

public void testToString() {

    Address a1 = new Address(1, "Main Road",

         "Vicksburg", 57332, "USA");

    Address a2 = new Address(2, "West Road",

          "Mobile", 44332, "USA");

    assertEquals(a1.toString(), "1 Main Road, Vicksburg, USA\n");

    assertEquals(a2.toString(), "2 West Road, Mobile, USA\n");

}

 

 

 

 

 

@Test

public void testSort() {

    Address a1 = new Address(1, "Main Road",

        "Vicksburg", 57332, "USA");

    Address a2 = new Address(1, "Main Road",

         "Mobile", 65544, "USA");

    Address a3 = new Address(2, "Main Road",

         "Los Angeles", 90787, "USA");

    List<Address> addresses = Arrays.asList(a1, a2, a3);

    Collections.sort(addresses);

    assertEquals(a1, addresses.get(2));

    assertEquals(a3, addresses.get(0));

}