SlideShare a Scribd company logo
1 of 12
Download to read offline
I am trying to cover the protected synchronized boolean enoughIngredients(Recipe r) method in
my inventoryTest file. But it doesn't reach the code. I tried making a child class in my
InventoryTest class extending the Inventory class and overrriding the method in the Inventory
class using a public modifier, but it still wouldn't work. I tried changing the access modifier of
enoughIngredients() to public as a test in the Inventory class but it still didn't work. Why aren't I
reaching the code? Do it have something to do with boolean as the method type? Thank you
public class Inventory {
private static int coffee;
private static int milk;
private static int sugar;
private static int chocolate;
public Inventory() {
setCoffee(15);
setMilk(15);
setSugar(15);
setChocolate(15);
}
public int getChocolate() {
return chocolate;
}
public synchronized void setChocolate(int chocolate) {
if (chocolate >= 0) {
Inventory.chocolate = chocolate;
}
}
public synchronized void addChocolate(String chocolate) throws InventoryException {
int amtChocolate = 0;
try {
amtChocolate = Integer.parseInt(chocolate);
} catch (NumberFormatException e) {
throw new InventoryException("Units of chocolate must be a positive integer");
}
if (amtChocolate >= 0) {
Inventory.chocolate += amtChocolate;
} else {
throw new InventoryException("Units of chocolate must be a positive integer");
}
}
public int getCoffee() {
return coffee;
}
public synchronized void setCoffee(int coffee) {
if (coffee >= 0) {
Inventory.coffee = coffee;
}
}
public synchronized void addCoffee(String coffee) throws InventoryException {
int amtCoffee = 0;
try {
amtCoffee = Integer.parseInt(coffee);
} catch (NumberFormatException e) {
throw new InventoryException("Units of coffee must be a positive integer");
}
if (amtCoffee >= 0) {
Inventory.coffee += amtCoffee;
} else {
throw new InventoryException("Units of coffee must be a positive integer");
}
}
public int getMilk() {
return milk;
}
public synchronized void setMilk(int milk) {
if (milk >= 0) {
Inventory.milk = milk;
}
}
public synchronized void addMilk(String milk) throws InventoryException {
int amtMilk = 0;
try {
amtMilk = Integer.parseInt(milk);
} catch (NumberFormatException e) {
throw new InventoryException("Units of milk must be a positive integer");
}
if (amtMilk >= 0) {
Inventory.milk += amtMilk;
} else {
throw new InventoryException("Units of milk must be a positive integer");
}
}
public int getSugar() {
return sugar;
}
public synchronized void setSugar(int sugar) {
if (sugar >= 0) {
Inventory.sugar = sugar;
}
}
public synchronized void addSugar(String sugar) throws InventoryException {
int amtSugar = 0;
try {
amtSugar = Integer.parseInt(sugar);
} catch (NumberFormatException e) {
throw new InventoryException("Units of sugar must be a positive integer");
}
if (amtSugar >= 0) {
Inventory.sugar += amtSugar;
} else {
throw new InventoryException("Units of sugar must be a positive integer");
}
}
protected synchronized boolean enoughIngredients(Recipe r) {
boolean isEnough = true;
if (Inventory.coffee < r.getAmtCoffee()) {
isEnough = false;
}
if (Inventory.milk < r.getAmtMilk()) {
isEnough = false;
}
if (Inventory.sugar < r.getAmtSugar()) {
isEnough = false;
}
if (Inventory.chocolate < r.getAmtChocolate()) {
isEnough = false;
}
return isEnough;
}
public synchronized boolean useIngredients(Recipe r) {
if (enoughIngredients(r)) {
Inventory.coffee -= r.getAmtCoffee();
Inventory.milk -= r.getAmtMilk();
Inventory.sugar -= r.getAmtSugar();
Inventory.chocolate -= r.getAmtChocolate();
return true;
} else {
return false;
}
}
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append("Coffee: ");
buf.append(getCoffee());
buf.append("n");
buf.append("Milk: ");
buf.append(getMilk());
buf.append("n");
buf.append("Sugar: ");
buf.append(getSugar());
buf.append("n");
buf.append("Chocolate: ");
buf.append(getChocolate());
buf.append("n");
return buf.toString();
}
}
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class InventoryTest {
@BeforeAll
static void setUpBeforeClass() throws Exception {
}
@AfterAll
static void tearDownAfterClass() throws Exception {
}
@BeforeEach
void setUp() throws Exception {
}
@AfterEach
void tearDown() throws Exception {
}
@Test
public void addCoffeeTest() throws InventoryException {
Inventory inventory = new Inventory();
String coffeeString = "15";
inventory.addCoffee(coffeeString);
int amtCoffee = Integer.parseInt(coffeeString);
int coffee = inventory.getCoffee();
if (amtCoffee >= 0) {
coffee += amtCoffee;
}
int expectedOutput = 45;
assertEquals(expectedOutput, coffee);
}
@Test
public void addMilkTest() throws InventoryException {
Inventory inventory = new Inventory();
String milkString = "15";
inventory.addMilk(milkString);
int amtMilk = Integer.parseInt(milkString);
int milk = inventory.getMilk();
if (amtMilk >= 0) {
milk += amtMilk;
}
int expectedOutput = 45;
assertEquals(expectedOutput, milk);
}
@Test
public void addSugarTest() throws InventoryException {
Inventory inventory = new Inventory();
String sugarString = "15";
inventory.addSugar(sugarString);
int amtSugar = Integer.parseInt(sugarString);
int sugar = inventory.getSugar();
if (amtSugar >= 0) {
sugar += amtSugar;
}
int expectedOutput = 45;
assertEquals(expectedOutput, sugar);
}
@Test
public void addChocolateTest() throws InventoryException {
Inventory inventory = new Inventory();
String chocolateString = "15";
inventory.addChocolate(chocolateString);
int amtChocolate = Integer.parseInt(chocolateString);
int chocolate = inventory.getChocolate();
if (amtChocolate >= 0) {
chocolate += amtChocolate;
}
int expectedOutput = 45;
assertEquals(expectedOutput, chocolate);
}
@Test
public boolean testForEnoughIngredients(Recipe r) throws InventoryException {
Inventory inventory = new Inventory();
boolean isEnough = true;
if (inventory.getCoffee() < r.getAmtCoffee()) {
isEnough = false;
}
if (inventory.getMilk() < r.getAmtMilk()) {
isEnough = false;
}
if (inventory.getSugar() < r.getAmtSugar()) {
isEnough = false;
}
if (inventory.getChocolate() < r.getAmtChocolate()) {
isEnough = false;
}
assertFalse(isEnough);
return isEnough;
}
}
public class Recipe {
private String name;
private int price;
private int amtCoffee;
private int amtMilk;
private int amtSugar;
private int amtChocolate;
public Recipe() {
this.name = "";
this.price = 0;
this.amtCoffee = 0;
this.amtMilk = 0;
this.amtSugar = 0;
this.amtChocolate = 0;
}
public int getAmtChocolate() {
return amtChocolate;
}
public void setAmtChocolate(String chocolate) throws RecipeException {
int amtChocolate = 0;
try {
amtChocolate = Integer.parseInt(chocolate);
} catch (NumberFormatException e) {
throw new RecipeException("Units of chocolate must be a positive integer");
}
if (amtChocolate >= 0) {
this.amtChocolate = amtChocolate;
} else {
throw new RecipeException("Units of chocolate must be a positive integer");
}
}
public int getAmtCoffee() {
return amtCoffee;
}
public void setAmtCoffee(String coffee) throws RecipeException {
int amtCoffee = 0;
try {
amtCoffee = Integer.parseInt(coffee);
} catch (NumberFormatException e) {
throw new RecipeException("Units of coffee must be a positive integer");
}
if (amtCoffee >= 0) {
this.amtCoffee = amtCoffee;
} else {
throw new RecipeException("Units of coffee must be a positive integer");
}
}
public int getAmtMilk() {
return amtMilk;
}
public void setAmtMilk(String milk) throws RecipeException {
int amtMilk = 0;
try {
amtMilk = Integer.parseInt(milk);
} catch (NumberFormatException e) {
throw new RecipeException("Units of milk must be a positive integer");
}
if (amtMilk >= 0) {
this.amtMilk = amtMilk;
} else {
throw new RecipeException("Units of milk must be a positive integer");
}
}
public int getAmtSugar() {
return amtSugar;
}
public void setAmtSugar(String sugar) throws RecipeException {
int amtSugar = 0;
try {
amtSugar = Integer.parseInt(sugar);
} catch (NumberFormatException e) {
throw new RecipeException("Units of sugar must be a positive integer");
}
if (amtSugar >= 0) {
this.amtSugar = amtSugar;
} else {
throw new RecipeException("Units of sugar must be a positive integer");
}
}
public String getName() {
return name;
}
public void setName(String name) {
if (name != null) {
this.name = name;
}
}
public int getPrice() {
return price;
}

More Related Content

Similar to I am trying to cover the protected synchronized boolean enoughIngred.pdf

For this homework, you will develop a class called VendingMachine th.pdf
For this homework, you will develop a class called VendingMachine th.pdfFor this homework, you will develop a class called VendingMachine th.pdf
For this homework, you will develop a class called VendingMachine th.pdfinfo309708
 
import java.util.ArrayList;public class Checkout{private.docx
import java.util.ArrayList;public class Checkout{private.docximport java.util.ArrayList;public class Checkout{private.docx
import java.util.ArrayList;public class Checkout{private.docxAbhinav816839
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
Tests unitaires mock_kesako_20130516
Tests unitaires mock_kesako_20130516Tests unitaires mock_kesako_20130516
Tests unitaires mock_kesako_20130516SOAT
 
Dat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android TestingDat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android TestingSaúl Díaz González
 
Imagine a world without mocks
Imagine a world without mocksImagine a world without mocks
Imagine a world without mockskenbot
 
SQLite and ORM Binding - Part 1 - Transcript.pdf
SQLite and ORM Binding - Part 1 - Transcript.pdfSQLite and ORM Binding - Part 1 - Transcript.pdf
SQLite and ORM Binding - Part 1 - Transcript.pdfShaiAlmog1
 
From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the typeWim Godden
 
How to write clean tests
How to write clean testsHow to write clean tests
How to write clean testsDanylenko Max
 
Hello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdfHello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdffedosys
 
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdfdatabase propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdffashiionbeutycare
 
Introduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORMIntroduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORMJason Myers
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good TestsTomek Kaczanowski
 

Similar to I am trying to cover the protected synchronized boolean enoughIngred.pdf (20)

For this homework, you will develop a class called VendingMachine th.pdf
For this homework, you will develop a class called VendingMachine th.pdfFor this homework, you will develop a class called VendingMachine th.pdf
For this homework, you will develop a class called VendingMachine th.pdf
 
import java.util.ArrayList;public class Checkout{private.docx
import java.util.ArrayList;public class Checkout{private.docximport java.util.ArrayList;public class Checkout{private.docx
import java.util.ArrayList;public class Checkout{private.docx
 
Mutation Testing
Mutation TestingMutation Testing
Mutation Testing
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
Tests unitaires mock_kesako_20130516
Tests unitaires mock_kesako_20130516Tests unitaires mock_kesako_20130516
Tests unitaires mock_kesako_20130516
 
Google guava
Google guavaGoogle guava
Google guava
 
Dat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android TestingDat testing - An introduction to Java and Android Testing
Dat testing - An introduction to Java and Android Testing
 
Imagine a world without mocks
Imagine a world without mocksImagine a world without mocks
Imagine a world without mocks
 
SQLite and ORM Binding - Part 1 - Transcript.pdf
SQLite and ORM Binding - Part 1 - Transcript.pdfSQLite and ORM Binding - Part 1 - Transcript.pdf
SQLite and ORM Binding - Part 1 - Transcript.pdf
 
From typing the test to testing the type
From typing the test to testing the typeFrom typing the test to testing the type
From typing the test to testing the type
 
How to write clean tests
How to write clean testsHow to write clean tests
How to write clean tests
 
Hello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdfHello everyone,Im actually working on a fast food order program..pdf
Hello everyone,Im actually working on a fast food order program..pdf
 
Func up your code
Func up your codeFunc up your code
Func up your code
 
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdfdatabase propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
database propertiesjdbc.url=jdbcderbyBigJavaDB;create=true # .pdf
 
Introduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORMIntroduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORM
 
Java Programming: Loops
Java Programming: LoopsJava Programming: Loops
Java Programming: Loops
 
FunctionalInterfaces
FunctionalInterfacesFunctionalInterfaces
FunctionalInterfaces
 
FunctionalInterfaces
FunctionalInterfacesFunctionalInterfaces
FunctionalInterfaces
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 

More from allystraders

Supplemental knowledge conversion processes have been added to the E.pdf
Supplemental knowledge conversion processes have been added to the E.pdfSupplemental knowledge conversion processes have been added to the E.pdf
Supplemental knowledge conversion processes have been added to the E.pdfallystraders
 
Supongamos que Musashi, un economista de un programa de radio AM, y .pdf
Supongamos que Musashi, un economista de un programa de radio AM, y .pdfSupongamos que Musashi, un economista de un programa de radio AM, y .pdf
Supongamos que Musashi, un economista de un programa de radio AM, y .pdfallystraders
 
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdf
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdfSuponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdf
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdfallystraders
 
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdf
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdfSuponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdf
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdfallystraders
 
Suppose researchers are about to draw a sample of 1450 observations .pdf
Suppose researchers are about to draw a sample of 1450 observations .pdfSuppose researchers are about to draw a sample of 1450 observations .pdf
Suppose researchers are about to draw a sample of 1450 observations .pdfallystraders
 
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdf
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdfSuponga que el Congreso est� considerando un proyecto de ley que imp.pdf
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdfallystraders
 
Suppose that there are two groups of people in the economy. In group.pdf
Suppose that there are two groups of people in the economy. In group.pdfSuppose that there are two groups of people in the economy. In group.pdf
Suppose that there are two groups of people in the economy. In group.pdfallystraders
 
Suppose that the Fed will increase the money supply. Which of the fo.pdf
Suppose that the Fed will increase the money supply. Which of the fo.pdfSuppose that the Fed will increase the money supply. Which of the fo.pdf
Suppose that the Fed will increase the money supply. Which of the fo.pdfallystraders
 
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdf
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdfSuppose that the body weights of Roborovski dwarf hamsters are norma.pdf
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdfallystraders
 
Suppose that in a particular country, the TFR fell to zero and remai.pdf
Suppose that in a particular country, the TFR fell to zero and remai.pdfSuppose that in a particular country, the TFR fell to zero and remai.pdf
Suppose that in a particular country, the TFR fell to zero and remai.pdfallystraders
 
Suppose that disposable income, consumption, and saving in some coun.pdf
Suppose that disposable income, consumption, and saving in some coun.pdfSuppose that disposable income, consumption, and saving in some coun.pdf
Suppose that disposable income, consumption, and saving in some coun.pdfallystraders
 
Suppose that 60 of students at Kansas State University have listene.pdf
Suppose that 60 of students at Kansas State University have listene.pdfSuppose that 60 of students at Kansas State University have listene.pdf
Suppose that 60 of students at Kansas State University have listene.pdfallystraders
 
Suppose Maria and Jamal both face the following individual loss dist.pdf
Suppose Maria and Jamal both face the following individual loss dist.pdfSuppose Maria and Jamal both face the following individual loss dist.pdf
Suppose Maria and Jamal both face the following individual loss dist.pdfallystraders
 
Suppose a random variable X has the following probability distributi.pdf
Suppose a random variable X has the following probability distributi.pdfSuppose a random variable X has the following probability distributi.pdf
Suppose a random variable X has the following probability distributi.pdfallystraders
 
Suppose a country had a smaller increase in debt in 2011 than it had.pdf
Suppose a country had a smaller increase in debt in 2011 than it had.pdfSuppose a country had a smaller increase in debt in 2011 than it had.pdf
Suppose a country had a smaller increase in debt in 2011 than it had.pdfallystraders
 
how would implement empowerment techniques within a service Choose .pdf
how would implement empowerment techniques within a service Choose .pdfhow would implement empowerment techniques within a service Choose .pdf
how would implement empowerment techniques within a service Choose .pdfallystraders
 
How were the management controls at Siemens prior to the Bribery sca.pdf
How were the management controls at Siemens prior to the Bribery sca.pdfHow were the management controls at Siemens prior to the Bribery sca.pdf
How were the management controls at Siemens prior to the Bribery sca.pdfallystraders
 
How would I create this diagramRentTool Viewpoints � Technology .pdf
How would I create this diagramRentTool Viewpoints � Technology .pdfHow would I create this diagramRentTool Viewpoints � Technology .pdf
How would I create this diagramRentTool Viewpoints � Technology .pdfallystraders
 
How well did Thaldorf interact with each member of the DMUOn what.pdf
How well did Thaldorf interact with each member of the DMUOn what.pdfHow well did Thaldorf interact with each member of the DMUOn what.pdf
How well did Thaldorf interact with each member of the DMUOn what.pdfallystraders
 
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdf
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdfHow do increasing atmospheric CO2 emissions threaten sea creatures, .pdf
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdfallystraders
 

More from allystraders (20)

Supplemental knowledge conversion processes have been added to the E.pdf
Supplemental knowledge conversion processes have been added to the E.pdfSupplemental knowledge conversion processes have been added to the E.pdf
Supplemental knowledge conversion processes have been added to the E.pdf
 
Supongamos que Musashi, un economista de un programa de radio AM, y .pdf
Supongamos que Musashi, un economista de un programa de radio AM, y .pdfSupongamos que Musashi, un economista de un programa de radio AM, y .pdf
Supongamos que Musashi, un economista de un programa de radio AM, y .pdf
 
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdf
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdfSuponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdf
Suponga que las tasas de inter�s en los Estados Unidos, pero no aume.pdf
 
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdf
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdfSuponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdf
Suponga que la ARN polimerasa estaba transcribiendo un gen eucari�ti.pdf
 
Suppose researchers are about to draw a sample of 1450 observations .pdf
Suppose researchers are about to draw a sample of 1450 observations .pdfSuppose researchers are about to draw a sample of 1450 observations .pdf
Suppose researchers are about to draw a sample of 1450 observations .pdf
 
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdf
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdfSuponga que el Congreso est� considerando un proyecto de ley que imp.pdf
Suponga que el Congreso est� considerando un proyecto de ley que imp.pdf
 
Suppose that there are two groups of people in the economy. In group.pdf
Suppose that there are two groups of people in the economy. In group.pdfSuppose that there are two groups of people in the economy. In group.pdf
Suppose that there are two groups of people in the economy. In group.pdf
 
Suppose that the Fed will increase the money supply. Which of the fo.pdf
Suppose that the Fed will increase the money supply. Which of the fo.pdfSuppose that the Fed will increase the money supply. Which of the fo.pdf
Suppose that the Fed will increase the money supply. Which of the fo.pdf
 
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdf
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdfSuppose that the body weights of Roborovski dwarf hamsters are norma.pdf
Suppose that the body weights of Roborovski dwarf hamsters are norma.pdf
 
Suppose that in a particular country, the TFR fell to zero and remai.pdf
Suppose that in a particular country, the TFR fell to zero and remai.pdfSuppose that in a particular country, the TFR fell to zero and remai.pdf
Suppose that in a particular country, the TFR fell to zero and remai.pdf
 
Suppose that disposable income, consumption, and saving in some coun.pdf
Suppose that disposable income, consumption, and saving in some coun.pdfSuppose that disposable income, consumption, and saving in some coun.pdf
Suppose that disposable income, consumption, and saving in some coun.pdf
 
Suppose that 60 of students at Kansas State University have listene.pdf
Suppose that 60 of students at Kansas State University have listene.pdfSuppose that 60 of students at Kansas State University have listene.pdf
Suppose that 60 of students at Kansas State University have listene.pdf
 
Suppose Maria and Jamal both face the following individual loss dist.pdf
Suppose Maria and Jamal both face the following individual loss dist.pdfSuppose Maria and Jamal both face the following individual loss dist.pdf
Suppose Maria and Jamal both face the following individual loss dist.pdf
 
Suppose a random variable X has the following probability distributi.pdf
Suppose a random variable X has the following probability distributi.pdfSuppose a random variable X has the following probability distributi.pdf
Suppose a random variable X has the following probability distributi.pdf
 
Suppose a country had a smaller increase in debt in 2011 than it had.pdf
Suppose a country had a smaller increase in debt in 2011 than it had.pdfSuppose a country had a smaller increase in debt in 2011 than it had.pdf
Suppose a country had a smaller increase in debt in 2011 than it had.pdf
 
how would implement empowerment techniques within a service Choose .pdf
how would implement empowerment techniques within a service Choose .pdfhow would implement empowerment techniques within a service Choose .pdf
how would implement empowerment techniques within a service Choose .pdf
 
How were the management controls at Siemens prior to the Bribery sca.pdf
How were the management controls at Siemens prior to the Bribery sca.pdfHow were the management controls at Siemens prior to the Bribery sca.pdf
How were the management controls at Siemens prior to the Bribery sca.pdf
 
How would I create this diagramRentTool Viewpoints � Technology .pdf
How would I create this diagramRentTool Viewpoints � Technology .pdfHow would I create this diagramRentTool Viewpoints � Technology .pdf
How would I create this diagramRentTool Viewpoints � Technology .pdf
 
How well did Thaldorf interact with each member of the DMUOn what.pdf
How well did Thaldorf interact with each member of the DMUOn what.pdfHow well did Thaldorf interact with each member of the DMUOn what.pdf
How well did Thaldorf interact with each member of the DMUOn what.pdf
 
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdf
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdfHow do increasing atmospheric CO2 emissions threaten sea creatures, .pdf
How do increasing atmospheric CO2 emissions threaten sea creatures, .pdf
 

Recently uploaded

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 

Recently uploaded (20)

Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

I am trying to cover the protected synchronized boolean enoughIngred.pdf

  • 1. I am trying to cover the protected synchronized boolean enoughIngredients(Recipe r) method in my inventoryTest file. But it doesn't reach the code. I tried making a child class in my InventoryTest class extending the Inventory class and overrriding the method in the Inventory class using a public modifier, but it still wouldn't work. I tried changing the access modifier of enoughIngredients() to public as a test in the Inventory class but it still didn't work. Why aren't I reaching the code? Do it have something to do with boolean as the method type? Thank you public class Inventory { private static int coffee; private static int milk; private static int sugar; private static int chocolate; public Inventory() { setCoffee(15); setMilk(15); setSugar(15); setChocolate(15); } public int getChocolate() { return chocolate; } public synchronized void setChocolate(int chocolate) { if (chocolate >= 0) { Inventory.chocolate = chocolate; } }
  • 2. public synchronized void addChocolate(String chocolate) throws InventoryException { int amtChocolate = 0; try { amtChocolate = Integer.parseInt(chocolate); } catch (NumberFormatException e) { throw new InventoryException("Units of chocolate must be a positive integer"); } if (amtChocolate >= 0) { Inventory.chocolate += amtChocolate; } else { throw new InventoryException("Units of chocolate must be a positive integer"); } } public int getCoffee() { return coffee; } public synchronized void setCoffee(int coffee) { if (coffee >= 0) { Inventory.coffee = coffee; } } public synchronized void addCoffee(String coffee) throws InventoryException { int amtCoffee = 0; try { amtCoffee = Integer.parseInt(coffee); } catch (NumberFormatException e) { throw new InventoryException("Units of coffee must be a positive integer"); } if (amtCoffee >= 0) { Inventory.coffee += amtCoffee; } else {
  • 3. throw new InventoryException("Units of coffee must be a positive integer"); } } public int getMilk() { return milk; } public synchronized void setMilk(int milk) { if (milk >= 0) { Inventory.milk = milk; } } public synchronized void addMilk(String milk) throws InventoryException { int amtMilk = 0; try { amtMilk = Integer.parseInt(milk); } catch (NumberFormatException e) { throw new InventoryException("Units of milk must be a positive integer"); } if (amtMilk >= 0) { Inventory.milk += amtMilk; } else { throw new InventoryException("Units of milk must be a positive integer"); } } public int getSugar() { return sugar; }
  • 4. public synchronized void setSugar(int sugar) { if (sugar >= 0) { Inventory.sugar = sugar; } } public synchronized void addSugar(String sugar) throws InventoryException { int amtSugar = 0; try { amtSugar = Integer.parseInt(sugar); } catch (NumberFormatException e) { throw new InventoryException("Units of sugar must be a positive integer"); } if (amtSugar >= 0) { Inventory.sugar += amtSugar; } else { throw new InventoryException("Units of sugar must be a positive integer"); } } protected synchronized boolean enoughIngredients(Recipe r) { boolean isEnough = true; if (Inventory.coffee < r.getAmtCoffee()) { isEnough = false; } if (Inventory.milk < r.getAmtMilk()) { isEnough = false; } if (Inventory.sugar < r.getAmtSugar()) { isEnough = false; } if (Inventory.chocolate < r.getAmtChocolate()) { isEnough = false;
  • 5. } return isEnough; } public synchronized boolean useIngredients(Recipe r) { if (enoughIngredients(r)) { Inventory.coffee -= r.getAmtCoffee(); Inventory.milk -= r.getAmtMilk(); Inventory.sugar -= r.getAmtSugar(); Inventory.chocolate -= r.getAmtChocolate(); return true; } else { return false; } } public String toString() { StringBuffer buf = new StringBuffer(); buf.append("Coffee: "); buf.append(getCoffee()); buf.append("n"); buf.append("Milk: "); buf.append(getMilk()); buf.append("n"); buf.append("Sugar: "); buf.append(getSugar()); buf.append("n"); buf.append("Chocolate: "); buf.append(getChocolate()); buf.append("n"); return buf.toString(); } } import static org.junit.jupiter.api.Assertions.*;
  • 6. import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class InventoryTest { @BeforeAll static void setUpBeforeClass() throws Exception { } @AfterAll static void tearDownAfterClass() throws Exception { } @BeforeEach void setUp() throws Exception { } @AfterEach void tearDown() throws Exception { } @Test public void addCoffeeTest() throws InventoryException { Inventory inventory = new Inventory(); String coffeeString = "15"; inventory.addCoffee(coffeeString); int amtCoffee = Integer.parseInt(coffeeString); int coffee = inventory.getCoffee(); if (amtCoffee >= 0) { coffee += amtCoffee; } int expectedOutput = 45; assertEquals(expectedOutput, coffee);
  • 7. } @Test public void addMilkTest() throws InventoryException { Inventory inventory = new Inventory(); String milkString = "15"; inventory.addMilk(milkString); int amtMilk = Integer.parseInt(milkString); int milk = inventory.getMilk(); if (amtMilk >= 0) { milk += amtMilk; } int expectedOutput = 45; assertEquals(expectedOutput, milk); } @Test public void addSugarTest() throws InventoryException { Inventory inventory = new Inventory(); String sugarString = "15"; inventory.addSugar(sugarString); int amtSugar = Integer.parseInt(sugarString); int sugar = inventory.getSugar(); if (amtSugar >= 0) { sugar += amtSugar; } int expectedOutput = 45; assertEquals(expectedOutput, sugar); }
  • 8. @Test public void addChocolateTest() throws InventoryException { Inventory inventory = new Inventory(); String chocolateString = "15"; inventory.addChocolate(chocolateString); int amtChocolate = Integer.parseInt(chocolateString); int chocolate = inventory.getChocolate(); if (amtChocolate >= 0) { chocolate += amtChocolate; } int expectedOutput = 45; assertEquals(expectedOutput, chocolate); } @Test public boolean testForEnoughIngredients(Recipe r) throws InventoryException { Inventory inventory = new Inventory(); boolean isEnough = true; if (inventory.getCoffee() < r.getAmtCoffee()) { isEnough = false; } if (inventory.getMilk() < r.getAmtMilk()) { isEnough = false; } if (inventory.getSugar() < r.getAmtSugar()) { isEnough = false; } if (inventory.getChocolate() < r.getAmtChocolate()) { isEnough = false; } assertFalse(isEnough); return isEnough;
  • 9. } } public class Recipe { private String name; private int price; private int amtCoffee; private int amtMilk; private int amtSugar; private int amtChocolate; public Recipe() { this.name = ""; this.price = 0; this.amtCoffee = 0; this.amtMilk = 0; this.amtSugar = 0; this.amtChocolate = 0; } public int getAmtChocolate() { return amtChocolate; } public void setAmtChocolate(String chocolate) throws RecipeException { int amtChocolate = 0; try { amtChocolate = Integer.parseInt(chocolate); } catch (NumberFormatException e) { throw new RecipeException("Units of chocolate must be a positive integer"); } if (amtChocolate >= 0) { this.amtChocolate = amtChocolate;
  • 10. } else { throw new RecipeException("Units of chocolate must be a positive integer"); } } public int getAmtCoffee() { return amtCoffee; } public void setAmtCoffee(String coffee) throws RecipeException { int amtCoffee = 0; try { amtCoffee = Integer.parseInt(coffee); } catch (NumberFormatException e) { throw new RecipeException("Units of coffee must be a positive integer"); } if (amtCoffee >= 0) { this.amtCoffee = amtCoffee; } else { throw new RecipeException("Units of coffee must be a positive integer"); } } public int getAmtMilk() { return amtMilk; } public void setAmtMilk(String milk) throws RecipeException { int amtMilk = 0; try { amtMilk = Integer.parseInt(milk); } catch (NumberFormatException e) {
  • 11. throw new RecipeException("Units of milk must be a positive integer"); } if (amtMilk >= 0) { this.amtMilk = amtMilk; } else { throw new RecipeException("Units of milk must be a positive integer"); } } public int getAmtSugar() { return amtSugar; } public void setAmtSugar(String sugar) throws RecipeException { int amtSugar = 0; try { amtSugar = Integer.parseInt(sugar); } catch (NumberFormatException e) { throw new RecipeException("Units of sugar must be a positive integer"); } if (amtSugar >= 0) { this.amtSugar = amtSugar; } else { throw new RecipeException("Units of sugar must be a positive integer"); } } public String getName() { return name; } public void setName(String name) {
  • 12. if (name != null) { this.name = name; } } public int getPrice() { return price; }