For Project 3
test these instance variables:
getAmtForPurchase
depositDime purchaseCandyBar
Provide traditional and unit tests. Ans:
// Traditional Test File: Test1.java
// Stan Smith
// Project 3
// Jan 23, 2020
public class Test1 {
public static void main(String[] args) {
// Write and test these two lines before
// typing anything else into your test file.
VendingMachine vm = new VendingMachine();
System.out.println(vm);
// Test depositDime, getAmtForPurchase, and
// purchaseCandyBar
vm.depositDime( );
vm.depositDime( );
vm.depositDime( );
vm.depositNickel( );
vm.depositQuarter( );
vm.depositQuarter( );
System.out.println(vm.getAmtForPurchase( ));
vm.loadCandyBars(5);
vm.purchaseCandyBar( );
System.out.println(vm);
}
}
/ Unit test file: Test2.java
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class Test2 {
private VendingMachine vm;
@BeforeEach
void setUp() {
vm = new VendingMachine( );
vm.loadCandyBars(5);
}
@Test
void testAmtForPurchase( ) {
assertEquals(0, vm.getAmtForPurchase( ));
}
@Test
void testDepositDime() {
vm.depositDime( );
assertEquals(10, vm.getAmtForPurchase( ));
}
@Test
public void testPurchaseCandyBar() {
for(int i = 1; i <= 3; i++) {
vm.depositQuarter( );
}
vm.purchaseCandyBar();
assertEquals(vm.toString( ),"4 0 Candy bar dispensed");
}
}