Hands On - JUNIT
Hands On - JUNIT
import java.util.*;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
@BeforeClass
public static void setUp(){
namelist.add("Arun");
namelist.add("Ashwin");
namelist.add("Anil");
namelist.add("Akash");
namelist.add("Azhar");
nameFinder=new NameFinder();
}
@Test
-----------------------------------------------------------------------------------
--------------------------------------
Search Product By Id:-
import java.util.*;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
@BeforeClass
public static void setUp(){
p1 =new Product(101,"Bag","A",1200);
p2 =new Product(102,"Wallet","B",700);
Product p3 =new Product(103,"Toys","C",400);
Product p4 =new Product(104,"Perfume","B",500);
p5 =new Product(105,"Books","A",2000);
productList.add(p1);
productList.add(p2);
productList.add(p3);
productList.add(p4);
productList.add(p5);
s=new Shop();
}
@Test
public void test11ViewProductByIdWhenExists() {
assertEquals(p1,s.viewProductById(productList,101));
}
@Test
public void test12ViewProductByIdWhenNotExists() {
assertEquals(null,s.viewProductById(productList,200));
}
}
-----------------------------------------------------------------------------------
-----------------------
Compute Membership Fees:-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.*;
@BeforeClass
public static void setUp() throws Exception {
@AfterClass
public static void tearDown() throws Exception {
}
@Test
public void testCollectMembershipFeesForNormal(){
}
@Test
public void testCollectMembershipFeesForPlatinum() {
Customer c=new Customer(1,"adarsh","733","Platinum");
assertEquals(125000,c.collectMembershipFees(),0.001);
}
}
-----------------------------------------------------
*----------------------------------------------------------------