Advertisement
ander758

GenerickStackTest

Sep 15th, 2019
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.38 KB | None | 0 0
  1. package Module02;
  2.  
  3. import org.junit.jupiter.api.BeforeEach;
  4. import org.junit.jupiter.api.Test;
  5.  
  6. import static org.hamcrest.MatcherAssert.assertThat;
  7. import static org.hamcrest.CoreMatchers.equalTo;
  8. import static org.hamcrest.CoreMatchers.is;
  9. import static org.junit.jupiter.api.Assertions.*;
  10.  
  11. class GenericStackTest {
  12.     private GenericStack genericStack;
  13.  
  14.     @BeforeEach
  15.     void setUp() {
  16.         genericStack = new GenericStack(100);
  17.     }
  18.  
  19.     @Test
  20.     void sizeMethodShouldReturnCorrectSizeOfArray() {
  21.         GenericStack<String> gsString = new GenericStack<>(100);
  22.         gsString.push("Java");
  23.         gsString.push("er");
  24.         gsString.push("morsomt! :D");
  25.         assertThat(gsString.size(), is(equalTo(3)));
  26.     }
  27.     @Test
  28.     void peekMethodShouldReturnLastElementInArray() {
  29.         GenericStack<String> gsString = new GenericStack<>(100);
  30.         gsString.push("First");
  31.         gsString.push("Second");
  32.         gsString.push("Last");
  33.         assertThat(gsString.peek(), is(equalTo("Last")));
  34.     }
  35.     @Test
  36.     void pushMethodShouldDoubleSizeOfArrayIfArrayIsFullWhenPushing() {
  37.         GenericStack<String> gsString = new GenericStack<>(100);
  38.         for (int i = 0; i < 100; i++) {
  39.             gsString.push("foo");
  40.         }
  41.         gsString.push("Fighters");
  42.         assertThat(gsString.size(), is(equalTo(100 * 2)));
  43.     }
  44.     @Test
  45.     void toStringMethodPrintsCorrectlyWithInteger() {
  46.         GenericStack<Integer> gsInteger = new GenericStack<>(100);
  47.         gsInteger.push(1);
  48.         gsInteger.push(2);
  49.         gsInteger.push(3);
  50.         assertThat(gsInteger.toString(), is(equalTo("[1, 2, 3]")));
  51.     }
  52.     @Test
  53.     void toStringMethodPrintsCorrectlyWithStrings() {
  54.         GenericStack<String> gsString = new GenericStack<>(100);
  55.         gsString.push("One");
  56.         gsString.push("Two");
  57.         gsString.push("Three");
  58.         assertThat(gsString.toString(), is(equalTo("[One, Two, Three]")));
  59.     }
  60.     @Test
  61.     void isEmptyMethodShouldReturnTrueIfElementsIsEmpty() {
  62.         assertTrue(genericStack.isEmpty());
  63.     }
  64.     /*@Test
  65.     void popMethodShouldRemoveLastElementInElements() {
  66.         GenericStack<Integer> gsString = new GenericStack<>(100);
  67.         gsString.push(1);
  68.         gsString.push(2);
  69.         gsString.push(3);
  70.         gsString.push(4);
  71.         gsString.push(5);
  72.         gsString.pop();
  73.  
  74.     }*/
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement