desislava_topuzakova

3. Iterator Test

Nov 26th, 2020
579
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package p03_IteratorTest;
  2.  
  3. import org.junit.Assert;
  4. import org.junit.Before;
  5. import org.junit.Test;
  6.  
  7. import javax.naming.OperationNotSupportedException;
  8.  
  9. public class ListIteratorTest {
  10.     private ListIterator listIterator;
  11.     private static final String[] DATA = {"X", "Y", "Z"};
  12.  
  13.     @Before
  14.     public void setUp() throws OperationNotSupportedException {
  15.         listIterator = new ListIterator(DATA);
  16.     }
  17.     //конструктор
  18.     //1. не му подаваме елементи (null)
  19.     @Test(expected = OperationNotSupportedException.class)
  20.     public void testCreateListWithNullParam() throws OperationNotSupportedException {
  21.         new ListIterator(null);
  22.     }
  23.     //2. да работи правилно
  24.     //hasNext
  25.     @Test
  26.     public void testHasNextReturnCorrectBoolean () {
  27.         //"X", "Y", "Z"
  28.         Assert.assertTrue(listIterator.hasNext());
  29.         listIterator.move();
  30.         Assert.assertTrue(listIterator.hasNext());
  31.         listIterator.move();
  32.         Assert.assertFalse(listIterator.hasNext());
  33.     }
  34.     //move
  35.     @Test
  36.     public void testMove() {
  37.         //"X", "Y", "Z"
  38.         Assert.assertTrue(listIterator.move());
  39.         Assert.assertTrue(listIterator.move());
  40.         Assert.assertFalse(listIterator.move());
  41.     }
  42.     //print
  43.     //1. ако няма елементи
  44.     @Test(expected = IllegalStateException.class)
  45.     public void testPrintEmptyList() throws OperationNotSupportedException {
  46.         ListIterator listIterator = new ListIterator();
  47.         listIterator.print();
  48.     }
  49.     //2. ako има елементи
  50.     @Test
  51.     public void testPrintCorrectly() {
  52.         int index = 0;
  53.         while(listIterator.hasNext()){
  54.             Assert.assertEquals(DATA[index], listIterator.print());
  55.             index++;
  56.             listIterator.move();
  57.         }
  58.     }
  59. }
  60.  
RAW Paste Data