Advertisement
Guest User

QueueTest

a guest
Jan 22nd, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package jUnitTestUnitaire;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import org.junit.Before;
  6. import org.junit.Test;
  7.  
  8. public class QueueTest {
  9.     Queue<String> fa0, fa1, fa2;
  10.  
  11.     @Before
  12.     public void setUp() throws Exception {
  13.         fa0 = new Queue<String>();
  14.  
  15.         fa1 = new Queue<String>();
  16.         fa1.push("plop");
  17.  
  18.         fa2 = new Queue<String>();
  19.         fa2.push("a");
  20.         fa2.push("b");
  21.     }
  22.  
  23.     @Test
  24.     public void testIsEmpty() {
  25.         assertTrue(fa0.isEmpty());
  26.         assertFalse(fa1.isEmpty());
  27.     }
  28.  
  29.     @Test
  30.     public void testPush() {
  31.         assertTrue(fa0.isEmpty());
  32.         fa0.push("toto");
  33.         assertFalse(fa0.isEmpty());
  34.     }
  35.  
  36.     @Test
  37.     public void testPop() throws Exception {
  38.         //exception
  39.         try{
  40.             fa0.pop();
  41.             fail();
  42.         }catch(Exception e){
  43.             //ok
  44.         }
  45.         assertEquals(fa1.pop(),"plop");
  46.         assertTrue(fa1.isEmpty());
  47.         assertEquals(fa2.pop(), "a");
  48.         assertEquals(fa2.pop(),"b");
  49.         assertTrue(fa2.isEmpty());
  50.     }
  51.    
  52.     @Test
  53.     public void TestFront() throws Exception {
  54.         try{
  55.             fa0.front();
  56.             fail();
  57.         }catch(Exception e){
  58.             //ok
  59.         }
  60.         assertEquals(fa1.front(),"plop");
  61.         assertTrue(fa1.isEmpty());
  62.         assertEquals(fa2.front(), "a");
  63.         assertEquals(fa2.front(),"b");
  64.         assertTrue(fa2.isEmpty());
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement