Package org.bigk.invoices.test.model

Source Code of org.bigk.invoices.test.model.PurchaserTest

package org.bigk.invoices.test.model;

import static org.junit.Assert.*;
import static org.bigk.invoices.model.builder.PurchaserBuilder.*;

import org.bigk.invoices.model.Purchaser;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;


@RunWith(JUnit4.class)
public class PurchaserTest {

  @Test
  public void neitherOfPurchaserEqualsNull() throws Exception {
    Purchaser aPurchaser = new Purchaser();
    assertFalse(aPurchaser.equals(null));
  }
 
  @Test
  public void twoPurchasersEqualByReference() throws Exception {
    Purchaser aPurchaser = new Purchaser();
    assertTrue(aPurchaser.equals(aPurchaser));
  }

  @Test
  public void twoPurchasersDifferWhenTheirFieldsDiffer() throws Exception {
   
    assertNotEquals(
        aPurchaser().withName("John").build(),
        aPurchaser().withName("Steve").build());
   
    assertNotEquals(
        aPurchaser().withName("John").withNip("12345").build(),
        aPurchaser().withName("John").withNip("67890").build());
   
    assertNotEquals(
        aPurchaser().withName("John").withNip("12345").build(),
        aPurchaser().withName("Steve").withNip("12345").build());
  }
 
  @Test
  public void twoPurchasersEqualWhenAllTheirFieldsEqual() throws Exception {
   
    Purchaser purchaserJohn = aPurchaser().withId(1L).withName("John")
        .withAddress("blah-blah 11").withNip("111-22-33-4444").build();
    Purchaser purchaserJohnAgain = aPurchaser().withId(1L).withName("John")
        .withAddress("blah-blah 11").withNip("111-22-33-4444").build();
   
    assertEquals(purchaserJohn, purchaserJohnAgain);
  }

  @Test
  public void purchaserEqualsHisSubclassWhenAllTheirFieldsEqual() throws Exception {
   
    Purchaser purchaserJohn = aPurchaser().withId(1L).withName("John")
        .withAddress("blah-blah 11").withNip("111-22-33-4444").build();
    Purchaser purchaserJohnSubclassed = new Purchaser() {
      // this is subclass of Purchaser.class
      private static final long serialVersionUID = 1L;
    };
    purchaserJohnSubclassed.setId(purchaserJohn.getId());
    purchaserJohnSubclassed.setName(purchaserJohn.getName());
    purchaserJohnSubclassed.setAddress(purchaserJohn.getAddress());
    purchaserJohnSubclassed.setNip(purchaserJohn.getNip());
       
    assertEquals(purchaserJohn, purchaserJohnSubclassed);
  }
}
TOP

Related Classes of org.bigk.invoices.test.model.PurchaserTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.