Junit And Mockito

Ace your studies with our custom writing services! We've got your back for top grades and timely submissions, so you can say goodbye to the stress. Trust us to get you there!


Order a Similar Paper Order a Different Paper

Junit And Mockito

Junit And Mockito
package com.lec.test;public interface Order {public double getPrice(FoodItem item);public double tax(double price);// 10% tax} package com.lec.test;public class FoodItem {private String menuId;private String name;private int quantity;public FoodItem(String menuId, String name, int quantity) {this.menuId = menuId;this.name = name;this.quantity = quantity; }public String getMenuId() {return menuId; }public void setMenuId(String menuId) {this.menuId = menuId; }public String getName() {return name; }public void setName(String name) {this.name = name; }public int getQuantity() {return quantity; }public void setQuantity(int quantity) {this.quantity = quantity; }} package com.lec.test;import java.util.List;public class OrderCart {private Order order;private List items;public Order getOrder() {return order; }public void setOrder(Order order) {this.order = order; }public List getItems() {return items; }public void setItems(List items) {this.items = items; }public double getTotalPrice(){double totalAmount = 0.0;for(FoodItem item:items){System.out.println(item.getName()+” “+ item.getQuantity()); totalAmount += order.getPrice(item) * item.getQuantity(); } totalAmount = totalAmount + order.tax(totalAmount);return totalAmount; }} The code above implement a “McDonald’s Ordering System”. Each branch can create its own menu but unfortunately, the price is determined by the head office. (FoodItem class is designed to create a menu but you should use Order interface to get the price of each menu. Also you can ask amount of tax using the same interface) Implementing the Order Interface is not your task. Your task is to test the “getTotalPrice” method. (Keep in mind, to test “getTotalPrice”, you should ask a price to head office using the Order interface) Test the “getTotalPrice” method using Mockito
Junit And Mockito
package com.lec.test;import java.util.ArrayList;import java.util.List;public class Math {public boolean isPrime(int n){boolean isPrime = true;for(int i = 2 ; 2*i < n ; i++){if(n%i == 0){ isPrime = false; } }return isPrime; }public boolean isPerfect(int x) {int sum = 0;for(int i = 1; i<=(x/2); i ++) {if(x%i == 0) { sum = sum + i; } }if(sum == x) {return true; }else {return false; } }public int[] bubbleSort(int[] num) {int j;boolean flag = true; // set flag to true to begin first passint temp; //holding variableSystem.out.println(“bubbleSort”);while (flag) { flag = false; //set flag to false awaiting a possible swapfor (j = 0; j < num.length – 1; j++) {if (num[j] < num[j + 1]) // change to > for ascending sort{ temp = num[j]; //swap elementsnum[j] = num[j + 1]; num[j + 1] = temp; flag = true; //shows a swap occurred} } }return num; }public int[] selectionSort(int[] num) {for (int i = 0; i < num.length – 1; i++) {int index = i;for (int j = i + 1; j < num.length; j++)if (num[j] < num[index]) index = j;int smallerNumber = num[index]; num[index] = num[i]; num[i] = smallerNumber; }return num; }public static int numZero(int[] x) {// Effects: if x == null throw NullPointerException // else return the number of occurrences of 0 in xint count = 0;for (int i = 1; i < x.length; i++) {if (x[i] == 0) { count++; } }return count; }public int findLast(int[] x, int y) {//Effects : if x = null throw nullPointerExceptions //else return the index of the last elements // in x that equals y // if no such element exists, return -1for(int i=x.length-1 ; i >0 ; i–) {if(x[i] == y) {return i; } }return -1; }public List getTodos(List list) {List filteredList = new ArrayList();for (String topic : list) {if (topic.contains(“coverage”)) {filteredList.add(topic); } }return filteredList; }} Design test cases for all operations in “Math” class Create the “math” instance(object) for testing by using “@Before” or “@BeforeEach” annotation. Write Junit testing code for each operation (@Test) Execute all test case with coverage and capture the screenshot of testing results The method percentage should be 100% The Line coverage should be more than 85% You can use “assertEquals” or “assertThat” type operation IntelliJ

Writerbay.net

Looking for top-notch essay writing services? We've got you covered! Connect with our writing experts today. Placing your order is easy, taking less than 5 minutes. Click below to get started.


Order a Similar Paper Order a Different Paper