电话:0731-83595998
导航

自动化测试的成功经验分享2

来源: 2017-11-26 13:18

此 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
  */

编辑推荐:

下载Word文档

温馨提示:因考试政策、内容不断变化与调整,长理培训网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准! (责任编辑:长理培训)

网络课程 新人注册送三重礼

已有 22658 名学员学习以下课程通过考试

网友评论(共0条评论)

请自觉遵守互联网相关政策法规,评论内容只代表网友观点!

最新评论

点击加载更多评论>>

精品课程

更多
10781人学习

免费试听更多

相关推荐
图书更多+
  • 电网书籍
  • 财会书籍
  • 其它工学书籍
拼团课程更多+
  • 电气拼团课程
  • 财会拼团课程
  • 其它工学拼团
热门排行

长理培训客户端 资讯,试题,视频一手掌握

去 App Store 免费下载 iOS 客户端