desislava_topuzakova

3. Iterator Test

Mar 22nd, 2022
1,241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.10 KB | None | 0 0
  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 = {"Desi", "Miroslav", "Boris", "Petar"};
  12.  
  13.     @Before
  14.     public void setup() throws OperationNotSupportedException {
  15.         listIterator = new ListIterator(DATA);
  16.     }
  17.     //1. конструктор
  18.     //1.1. празен списък с елементи
  19.     @Test(expected = OperationNotSupportedException.class)
  20.     public void testConstructorNullParam() throws OperationNotSupportedException {
  21.         new ListIterator(null);
  22.     }
  23.  
  24.     //2. hasNext + move
  25.     @Test
  26.     public void testMove () {
  27.         // {"Desi", "Miroslav", "Boris", "Petar"} -> current = 0
  28.         Assert.assertTrue(listIterator.hasNext());
  29.         Assert.assertTrue(listIterator.move());
  30.         //{"Desi", "Miroslav", "Boris", "Petar"} -> current = 1
  31.         Assert.assertTrue(listIterator.hasNext());
  32.         Assert.assertTrue(listIterator.move());
  33.         //{"Desi", "Miroslav", "Boris", "Petar"} -> current = 2
  34.         Assert.assertTrue(listIterator.hasNext());
  35.         Assert.assertTrue(listIterator.move());
  36.         //{"Desi", "Miroslav", "Boris", "Petar"} -> current = 3
  37.         Assert.assertFalse(listIterator.hasNext());
  38.         Assert.assertFalse(listIterator.move());
  39.     }
  40.  
  41.     //3. print
  42.     //3.1. празен списък с елементи
  43.     @Test (expected = IllegalStateException.class)
  44.     public void testPrintEmptyList () throws OperationNotSupportedException {
  45.         listIterator = new ListIterator();
  46.         listIterator.print();
  47.     }
  48.     //3.2. списък с елементи
  49.     @Test
  50.     public void testPrintCorrectly() {
  51.         //{"Desi", "Miroslav", "Boris", "Petar"} -> current = 0
  52.         int index = 0;
  53.         while (listIterator.hasNext()) {
  54.             Assert.assertEquals(listIterator.print(), DATA[index]);
  55.             index++;
  56.             listIterator.move(); //current += 1
  57.         }
  58.     }
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment