View Javadoc

    1   package org.example.customer.utility;
    2
    3   import static org.junit.Assert.assertEquals;
    4   import static org.junit.Assert.assertFalse;
    5   import static org.junit.Assert.assertNotNull;
    6   import static org.junit.Assert.assertTrue;
    7
    8   import org.apache.logging.log4j.Level;
    9   import org.apache.logging.log4j.LogManager;
    10  import org.apache.logging.log4j.core.config.Configurator;
    11  import org.junit.Before;
    12  import org.junit.BeforeClass;
    13  import org.junit.Test;
    14
    15  public class CustomerEntityTest
    16  {
    17      private CustomerEntity testCustomerEntity = null;
    18
    19      @BeforeClass // this runs only once before any test
    20      public static void setup()
    21      {
    22          Configurator.setLevel(LogManager.getLogger(CustomerEntity.class).getName(), Level.WARN);
    23      }
    24
    25      @Before
    26      public void setUp() throws Exception
    27      {
    28          testCustomerEntity = new CustomerEntity();
    29      }
    30
    31      @Test
    32      public void testCustomerEntityDefaultConstructor()
    33      {
    34          CustomerEntity defaultCustomerEntity = new CustomerEntity();
    35          assertNotNull(defaultCustomerEntity);
    36      }
    37
    38      @Test
    39      public void testDefaultId()
    40      {
    41          int expected = 1;
    42          int actual = testCustomerEntity.getId();
    43          assertEquals(expected, actual);
    44      }
    45
    46      @Test
    47      public void testValidId()
    48      {
    49          int[] good = { 2, 34, 999, 22, 1, 565656 };
    50          for (int entry : good)
    51          {
    52              testCustomerEntity.setId(entry);
    53          }
    54      }
    55
    56      @Test(expected = IllegalArgumentException.class)
    57      public void testInValidId()
    58      {
    59          testCustomerEntity.setId(0);
    60      }
    61
    62      @Test
    63      public void testToString()
    64      {
    65          String expected = "CustomerEntity [Id=1]";
    66          String actual = testCustomerEntity.toString();
    67          assertEquals(expected, actual);
    68      }
    69
    70      @Test public void testHashCode()
    71      {
    72          CustomerEntity sample = new CustomerEntity();
    73          int expected = sample.hashCode();
    74          int actual = testCustomerEntity.hashCode();
    75          assertEquals(expected, actual);
    76      }
    77
    78      @Test public void testEquals()
    79      {
    80          CustomerEntity sample = new CustomerEntity();
    81          assertTrue(testCustomerEntity.equals(sample));
    82      }
    83
    84      @Test public void testNotEquals()
    85      {
    86          CustomerEntity sample = new CustomerEntity();
    87          sample.setId(42);
    88          assertFalse(testCustomerEntity.equals(sample));
    89
    90          Object junk = new Object();
    91          assertFalse(testCustomerEntity.equals(junk));
    92      }
    93  }