Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Wojciech.z2;
- import org.junit.jupiter.api.BeforeAll;
- import org.junit.jupiter.api.BeforeEach;
- import org.junit.jupiter.api.DisplayName;
- import org.junit.jupiter.api.Test;
- import static org.junit.jupiter.api.Assertions.*;
- class fridgeStateTest {
- private fridgeState fs;
- @BeforeAll
- static void init(){
- System.out.println("Tests have been initialized.");
- }
- @BeforeEach
- void beforeEach(){
- System.out.println("Next test...");
- }
- @Test
- @DisplayName("Add an item")
- void addItem(){
- fs = new fridgeState();
- fs.items.add("Kot");
- assertTrue(fs.items.contains("Kot"));
- assertEquals("Kot",fs.items.get(0));
- }
- @Test
- @DisplayName("Remove an item with contains")
- void removeItem(){
- fs = new fridgeState();
- fs.items.add("Kot");
- fs.items.add("Pies");
- fs.items.remove("Kot");
- assertFalse(fs.items.contains("Kot"));
- }
- @Test
- @DisplayName("Remove an item with an exception")
- void removeItem2(){
- fs = new fridgeState();
- String kot = "Kot";
- fs.items.add(kot);
- fs.items.remove(kot);
- assertFalse(fs.items.contains(kot));
- assertTrue(fs.items.isEmpty());
- assertThrows(IndexOutOfBoundsException.class,()-> fs.items.get(0));
- }
- @Test
- @DisplayName("List is not an empty object")
- void emptyList(){
- fs = null;
- assertNotNull(fs,()->"Object is not empty");
- }
- }
- ==========================================================================================
- package Wojciech.z2;
- import java.util.ArrayList;
- import java.util.List;
- public class fridgeState {
- List<String> items = new ArrayList<String>();
- public void addItem(String i){
- items.add(i);
- }
- public void removeItem(String i){
- items.remove(i);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement