Question: Need to complete the program The testing code is below: import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue;
Need to complete the program


The testing code is below:
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue;
import java.lang.reflect.Method;
import org.junit.Rule; import org.junit.Test; import org.junit.rules.Timeout;
import edu.buffalo.correctness.Scorable;
/* * Homework test cases
* (C) 2018 by Matthew Hertz
* Posting this file to a website without the explicit written permission of the author is a violation of their * copyright. */
/** * This is actually a bad set of tests, since each class should only define tests for a single class. I am doing this * anyway, however, to simplify the work you must do on this weekly assignment. * * @author Matthew Hertz */ @Scorable(problem = "Homework03Problem3") public class PetTest {
// Test that the interface is properly defined. @Test public void testPet() throws SecurityException, NoSuchMethodException { Class> pet = Pet.class; assertTrue("Pet must be an interface!", pet.isInterface()); Method[] methods = pet.getMethods(); assertEquals("Pet should define 2 methods", 2, methods.length); Method howToCallMethod = pet.getMethod("howToCall", String.class); assertNotNull("Pet should define a method name formatName with a single String parameter", howToCallMethod); assertEquals("formatName should return a String", String.class, howToCallMethod.getReturnType()); Method preferredFoodMethod = pet.getMethod("preferredFood"); assertNotNull("Pet should define a method name noiseMade with no parameters", preferredFoodMethod); assertEquals("noiseMade should return a String", String.class, preferredFoodMethod.getReturnType()); }
// Test that your Dog class works and is properly defined. @Test public void testDog() { Class> dogClass = Dog.class; Class>[] interfaces = dogClass.getInterfaces(); assertEquals("Dog should only implement 1 class", 1, interfaces.length); assertEquals("Dog should implement the Pet interface", Pet.class, interfaces[0]); Dog dog = new Dog(); assertEquals("Come here Lassie", dog.howToCall("Lassie")); assertEquals("Come here Rover", dog.howToCall("Rover")); assertEquals("Kibble", dog.preferredFood()); }
// Test that your Cat class works and is properly defined. @Test public void testCat() { Class> catClass = Cat.class; Class>[] interfaces = catClass.getInterfaces(); assertEquals("Cat should only implement 1 class", 1, interfaces.length); assertEquals("Cat should implement the Pet interface", Pet.class, interfaces[0]); Cat cat = new Cat(); assertEquals("Open a can", cat.howToCall("Howard")); assertEquals("Open a can", cat.howToCall("Jack")); assertEquals("Meat", cat.preferredFood()); }
// Test that your Goat class works and is properly defined. @Test public void testGoat() { Class> goatClass = Goat.class; Class>[] interfaces = goatClass.getInterfaces(); assertEquals("Goat should only implement 1 class", 1, interfaces.length); assertEquals("Goat should implement the Pet interface", Pet.class, interfaces[0]); Goat goat = new Goat(); assertEquals("Todd to me", goat.howToCall("Todd")); assertEquals("LeBron James to me", goat.howToCall("LeBron James")); // LeBron is the GOAT assertEquals("EVERYTHING", goat.preferredFood()); } }
Problem #3-Interfaces As should now be habit, your interface and classes for this problem must be in the adi. buffala ea16 package Write an interface named Pet which declares a two methods: preterredFood) which will return a Strinc and hoTaCall (Strinc nse) which also returns a Strinc. You then need to write 4 classes that implement your Pet interface. The name and description of each of these classes is: Ta1 should return 'Come here, a space, and then the value of L' praterTaot method should return the String 'Kibble . Cst-borToCailO should return "Open a can", Cat'srat rrefood() method should return the String 'Meat Gaat--haeToC allo should return the value of nam, a space, and then "to me". Gc::$9rterredFoa() method should return the String 'EVERYTHING. rien--ho I t 11:) should return 11 you cannot call a fish. Theish class will also need to define a field named wild Of type balen You will also need to define a getter (named i and setter (named set: 1 for the instance variable. write a constructor forr e? that has a single "Flakes" when id is and the method returns 'Worms" whensis te. ul, para meter specifying if the instance is wildlish.Sy: f red",) method will return the String Download this jar file, The JAR file contains the ret Tost class of JUnit tests iwhich needs to be added to your project as before). PtTat includes most of the tests that AutoLab uses to grade your submission, but you will need to write your own JUnit tests to verify that your Fi class works correctly Make a zip file which includes your Fa: interface and the 4 classes you wrote which implement that interface. (Here are instructions for making a zip file on Mac OS and instructions to do this on Windows.) Submit this zip file to Autolab for Homework 03 Problem 3
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
