Question: lab6TestPart1 mentioned above--->> package test; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import bigcat.BigCat; import bigcat.BigCatBreed; class Lab6TestPart1 { static String sName =

 lab6TestPart1 mentioned above--->> package test; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.AfterAll; import

org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import bigcat.BigCat; import bigcat.BigCatBreed; class Lab6TestPart1 { static String

lab6TestPart1 mentioned above--->>

package test;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test;

import bigcat.BigCat; import bigcat.BigCatBreed;

class Lab6TestPart1 { static String sName = ""; // used for student name @BeforeAll static void setUpBeforeClass() throws Exception { sName = utils.MyUtils.getNameFromStudent(); System.out.println("Test for " + sName + " self-certified by " + sName); System.out.println("Testing for " + sName + " begins.."); }

@AfterAll static void tearDownAfterClass() throws Exception {

System.out.println("End of certified testing for " + sName + " ......."); } @Test public void test() { testConstructors(); testAccessorsAndModifiers(); }

public void testConstructors() { System.out.println(" ****Test Constructors *****"); BigCat cat1 = new BigCat(); System.out.println("Default cat1: " + cat1); assertEquals(BigCat.DEFAULT_NAME, cat1.getName()); assertEquals(BigCatBreed.HOUSE_CAT, cat1.getCatBreed()); assertEquals(0, cat1.getWeight()); BigCat cat2 = new BigCat(" ", BigCatBreed.CHEETAH, -5); assertEquals(BigCat.DEFAULT_NAME, cat2.getName(), "Name should default -- all blanks"); assertEquals(BigCatBreed.CHEETAH, cat2.getCatBreed(), "Breed should be CHEETAH"); assertEquals(0, cat2.getWeight(), "cat's weight should be 0 as -5 is not allowed"); BigCat cat3 = new BigCat(" princess preTTY ANNE ", BigCatBreed.BOBCAT,75); assertEquals("Princess Pretty Anne", cat3.getName(), "Name of cat should be properly formatted"); assertEquals(BigCatBreed.BOBCAT, cat3.getCatBreed()); assertEquals(75, cat3.getWeight());

cat3 = new BigCat(" crazy chief ", BigCatBreed.CHEETAH, BigCat.MAX_WEIGHT+1); assertEquals("Crazy Chief", cat3.getName(),"name should match Crazy Chief"); assertEquals(0, cat3.getWeight()); assertEquals(BigCatBreed.CHEETAH, cat3.getCatBreed()); System.out.println("Original cat3: " + cat3);

cat3 = new BigCat(" TomMY ", BigCatBreed.CHEETAH, 165); assertEquals("Tommy", cat3.getName(),"name should match Tommy"); assertEquals(165, cat3.getWeight()); assertEquals(BigCatBreed.CHEETAH, cat3.getCatBreed()); String str = "";

str = cat3.toString(); // NOTE toString() has to be added to BigCat class String res = "Tommy"; assertEquals(0, utils.MyUtils.numberLines(res)); assertTrue(str.contains(res)); res = "165"; assertTrue(str.contains(res)); res = "CHEETAH"; assertTrue(str.contains(res));

System.out.println("Newer modified cat3: " + cat3); System.out.println("****End of Constructors *****"); }

public void testAccessorsAndModifiers() { System.out.println(" ****Test Accessors/Modifiers *****"); BigCat cat3 = new BigCat(" JoEY SMARTY ", BigCatBreed.LION,175); System.out.println("cat3: " + cat3); assertEquals("Joey Smarty", cat3.getName()); assertEquals(BigCatBreed.LION, cat3.getCatBreed()); assertEquals(175, cat3.getWeight()); System.out.println(" Testing setCatBreed()"); cat3.setCatBreed(BigCatBreed.TIGER); assertEquals(BigCatBreed.TIGER, cat3.getCatBreed()); cat3.setCatBreed(BigCatBreed.HOUSE_CAT); assertEquals(BigCatBreed.HOUSE_CAT, cat3.getCatBreed()); cat3.setCatBreed(BigCatBreed.TIGER); assertEquals(BigCatBreed.TIGER, cat3.getCatBreed());

System.out.println(" Testing setName()"); cat3.setName(" "); assertEquals(BigCat.DEFAULT_NAME, cat3.getName()); cat3.setName(""); assertEquals(BigCat.DEFAULT_NAME, cat3.getName()); cat3.setName(" SPORT "); assertEquals("Sport", cat3.getName()); cat3.setName("CK "); assertEquals("Ck", cat3.getName());

System.out.println(" Testing setWeight()"); cat3.setWeight(-400); assertEquals(0, cat3.getWeight()); cat3.setWeight(1); assertEquals(1, cat3.getWeight()); cat3.setWeight(BigCat.MAX_WEIGHT + 1); assertEquals(0, cat3.getWeight()); cat3.setWeight(BigCat.MAX_WEIGHT); assertEquals(BigCat.MAX_WEIGHT, cat3.getWeight());

String result = cat3.toString(); assertTrue(result.contains(BigCat.MAX_WEIGHT + "")); // convert to string max weight assertTrue(result.contains("Ck")); assertTrue(result.contains("TIGER")); System.out.println("cat3: " + cat3); System.out.println("****End of Accessors/ModifiersTest *****"); } }

1. Create 3 packages for this lab, labb, utils, test. 2. In package labo, write a Java class named BigCat. Every BigCat instance has a name (String), and a cat breed, and a weight (int). 3. Create in package labb, an enum type, Big CatBreed with these declared values: LION, TIGER, CHEETAH, BOBCAT, HOUSE CAT 4. In your BigCat class a) Declare a public constant DEFAULT_NAME and assign it "$$$$" Declare a public int constant named MAX WEIGHT and assign it to be 2000; b) Declare private attributes for the Big Cat class as described above. c) Write a default (no argument) constructor for the BigCat class places DEFAULT_NAME, HOUSE_CAT, and O in the instance. c) Write a second constructor for the BigCat class that receives a name, cat breed, and weight. Trim the received name, properFormat it, and if empty string, set to default name value. The received weight has to be >=0 and =0 and

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 Databases Questions!