此 fixture 将调用下面清单中显示的 SUT(被测对象) CoffeeMaker 类,然后调用该类上的相关方法。
package cstc.fitexam.ffeemaker;
public class CoffeeMaker {
/**
* Array of recipes in coffee maker
*/
private Recipe [] recipeArray;
/** Number of recipes in coffee maker */
private final int NUM_RECIPES = 4;
/** Array describing if the array is full */
private boolean [] recipeFull;
/** Inventory of the coffee maker */
private Inventory inventory;
/**
* Constructor for the coffee maker
*
*/
public CoffeeMaker() {
recipeArray = new Recipe[NUM_RECIPES];
recipeFull = new boolean[NUM_RECIPES];
for(int i = 0; i < NUM_RECIPES; i++) {
recipeArray[i] = new Recipe();
recipeFull[i] = false;
}
inventory = new Inventory();
}
/**
* Returns true if a recipe is successfully added to the
* coffee maker
* @param r
* @return boolean
*/
public boolean addRecipe(Recipe r) {
boolean canAddRecipe = true;
//Check if the recipe already exists
for(int i = 0; i < NUM_RECIPES; i++) {
if(r.equals(recipeArray[i])) {
canAddRecipe = false;
}
}
//Check for an empty recipe, add recipe to first empty spot
if(canAddRecipe) {
int emptySpot = -1;
for(int i = 0; i < NUM_RECIPES; i++) {
if(!recipeFull[i]) {
emptySpot = i;
canAddRecipe = true;
}
}
if(emptySpot != -1) {
recipeArray[emptySpot] = r;
recipeFull[emptySpot] = true;
}
else {
canAddRecipe = false;
}
}
return canAddRecipe;
}
/**
* Returns true if the recipe was deleted from the
* coffee maker
* @param r
* @return boolean
*/
public boolean deleteRecipe(Recipe r) {
boolean canDeleteRecipe = false;
if(r != null) {
for(int i = 0; i < NUM_RECIPES; i++) {
if(r.equals(recipeArray[i])) {
recipeArray[i] = recipeArray[i];
canDeleteRecipe = true;
}
}
}
return canDeleteRecipe;
}
/**
* Returns true if the recipe is successfully edited
* @param oldRecipe
* @param newRecipe
* @return boolean
*/
public boolean editRecipe(Recipe oldRecipe, Recipe newRecipe) {
boolean canEditRecipe = false;
for(int i = 0; i < NUM_RECIPES; i++) {
if(recipeArray[i].getName() != null) {
if(newRecipe.equals(recipeArray[i])) {
recipeArray[i] = new Recipe();
if(addRecipe(newRecipe)) {
canEditRecipe = true;
} else {
//Unreachable lin
e of code
canEditRecipe = false;
}
}
}
}
return canEditRecipe;
}
/**
* Returns true if inventory was successfully added
* @param amtCoffee
* @param amtMilk
* @param amtSugar
* @param amtChocolate
* @return boolean
*/
编辑推荐:
![](http://m.zuixu.com/static/img/neirong2.jpg)
温馨提示:因考试政策、内容不断变化与调整,长理培训网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准! (责任编辑:长理培训)
点击加载更多评论>>