logo

Crowdly

Browser

Add to Chrome

Assume you specified the following test cases based on the requirements of an Io...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

Assume you specified the following test cases based on the requirements of an IoT (Internet of Things) system that is used for a smart home:

class TestMyIoTSystem {

    MyIoTSystem s = null;

    @BeforeEach

    void setUp() throws Exception {

        s = new MyIoTSystem("Home");

    }

    // Test: Adding a home automation item (name, quantity)

    @Test

    void test1() {

        s.add("Vacuum cleaner",2);

        assertTrue(s.has("Vacuum cleaner"));

    }

    

    // Test: Adding a home automation item, querying the quantity of the item in the system

    @Test

    void test2() {

        s.add("Irrigation system",1);

        assertEquals(1,s.getQuantity("Irrigation system"));

    }

    

    // Test: Adding a home automation item, removing an existing item

    @Test

    void test3() {

        s.add("Irrigation system",1); s.add("Vacuum cleaner",1);

        assertEquals("Removed successfully",s.remove("Vacuum cleaner"));

    }

     

    // Test: Adding a home automation item, removing a non-existing item which should throw an exception

    @Test

    void test4() {       

        s.add("Irrigation system",1);

        assertThrows(Exception.class, () -> s.remove("Vacuum cleaner"));

    }

}

The following code has been implemented to fulfill the test cases following test-driven development:

 public class MyIoTSystem {

    private final String name;

    private List<IoTComponent> list;

    

    private class IoTComponent {

        private String name;

        private int quantity;

        

        IoTComponent(String name, int quantity){

            this.name = name;

            this.quantity = quantity;

        }

        

        public String getName () {

            return name;

        }

        

        public int getQuantity() {

            return quantity;

        }

    }

    public MyIoTSystem(String string) {

        name = string;

        list = new ArrayList<>();

    }

    public void add(String name, int quantity) {

        list.add(new IoTComponent(name,quantity));

    }

    public boolean has(String string) {

        for (IoTComponent c : list){

            if (c.getName().compareTo(string) == 0) {

                return true;

            }

        }

        return false;

    }

    public String remove(String string) {

        for (IoTComponent c : list){

            if (c.getName().compareTo(string) == 0) {

                list.remove(c);

                return ("Removed successfully");

            }

        }

        return null;

    }

}

 

Which of the test cases need additional implementations to run successfully?

a) test1()

b) test2()

c) test3()

d) test4()

 

✅
❌
❌
❌
More questions like this

Want instant access to all verified answers on moodle.jku.at?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome