Advertisement
Guest User

Untitled

a guest
Nov 12th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. package Wojciech.z2;
  2.  
  3. import org.junit.jupiter.api.BeforeAll;
  4. import org.junit.jupiter.api.BeforeEach;
  5. import org.junit.jupiter.api.DisplayName;
  6. import org.junit.jupiter.api.Test;
  7. import static org.junit.jupiter.api.Assertions.*;
  8.  
  9. class fridgeStateTest {
  10.  
  11. private fridgeState fs;
  12.  
  13. @BeforeAll
  14. static void init(){
  15. System.out.println("Tests have been initialized.");
  16. }
  17.  
  18. @BeforeEach
  19. void beforeEach(){
  20. System.out.println("Next test...");
  21. }
  22.  
  23. @Test
  24. @DisplayName("Add an item")
  25. void addItem(){
  26. fs = new fridgeState();
  27.  
  28. fs.items.add("Kot");
  29. assertTrue(fs.items.contains("Kot"));
  30. assertEquals("Kot",fs.items.get(0));
  31. }
  32.  
  33. @Test
  34. @DisplayName("Remove an item with contains")
  35. void removeItem(){
  36. fs = new fridgeState();
  37.  
  38. fs.items.add("Kot");
  39. fs.items.add("Pies");
  40. fs.items.remove("Kot");
  41.  
  42. assertFalse(fs.items.contains("Kot"));
  43. }
  44.  
  45.  
  46. @Test
  47. @DisplayName("Remove an item with an exception")
  48. void removeItem2(){
  49. fs = new fridgeState();
  50. String kot = "Kot";
  51. fs.items.add(kot);
  52. fs.items.remove(kot);
  53.  
  54. assertFalse(fs.items.contains(kot));
  55. assertTrue(fs.items.isEmpty());
  56. assertThrows(IndexOutOfBoundsException.class,()-> fs.items.get(0));
  57. }
  58.  
  59. @Test
  60. @DisplayName("List is not an empty object")
  61. void emptyList(){
  62. fs = null;
  63. assertNotNull(fs,()->"Object is not empty");
  64. }
  65. }
  66.  
  67. ==========================================================================================
  68.  
  69. package Wojciech.z2;
  70.  
  71. import java.util.ArrayList;
  72. import java.util.List;
  73.  
  74. public class fridgeState {
  75.  
  76. List<String> items = new ArrayList<String>();
  77.  
  78. public void addItem(String i){
  79. items.add(i);
  80. }
  81.  
  82. public void removeItem(String i){
  83. items.remove(i);
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement