Question: please read all steps and also explain the answers I also posted the code photos and text version thank you Part2 11. Go back to

please read all steps and also explain the answers

I also posted the code photos and text version

thank you

Part2

11. Go back to Eclipse. Now take a look at Message.java and Mailbox.java. The Mailbox class manages a list of messages sent to a user. List and briefly

explain what each Mailbox method does (yes, you can look at the Javadoc comments)

12. Create JUnit test class for Message. Make sure the setup() option is checked. The methods you will be testing are getRecipient(), getSender, getText, and toString() - select those in the dialog box.

13. Run MessageTester. It should fail.

14. Now, add code to the setup() method. This code will look like this msgStr = "Test Message"; recip = "Frank"; sender ="Mary"; msg = new Message(sender, recip, msgStr); Also, add instance variables to MessageTester corresponding to the variables in the code above. 15. Now, fill in the code that tests getRecipient(). The method is testGetRecipient. The code should invoke the method getRecipient on the Message object created in setup() - the object name is msg. It should test the value returned by get Recipient to see if it is equal to the recipient stored in the instance variable recip. Describe how this test case works. 16. Fill in the code that tests getSender and getText. 17. Fill in the code that tests toString(). This is trickier because toString() returns a formatted string, and you need to write the test to check if it is the string you expect. The way to do is to create string named expectedResult, and assign to it the string you expect. Then, call toString() and test the result against the expectedResult.

18. Run your tester, and make sure it works.

19. Now, you are going to build a tester for the Mailbox class. Create the unit test class the same way as above. Make sure Setup is checked.

20. In the generated setup method, create instance of your mailbox. box = new Mailbox(owner); This will cause a fresh Mailbox object to be created before each test case. The Mailbox reference should be an instance variable of the test class.

21. Now, create tests for each of the Mailbox methods. For example, to test the isEmpty method, simply call isEmpty and test that it returns true, using assertTrue. public void testIsEmpty() {

assertTrue(box.isEmpty()); } This works because a newly created Mailbox is empty. You should also create test method that tests the return value of isEmpty when the Mailbox is NOT empty (add a message to the Mailbox and then test the return value of isEmpty).

22. To test getNextMessage, create message with known values, add it to the mailbox, then retrieve the next message by calling getNextMessage and test that the retrieved message has the same values as the one you added. You should also test that the retrieved message was removed from the mailbox. Q: If you add one message to an empty Mailbox and then retrieve it from the Mailbox, what method should you call to make sure the message was removed?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!