0% found this document useful (0 votes)
32 views3 pages

Hands On - JUNIT

The document contains test cases for three different Java classes - NameFinderTest, ShopTest, and CustomerTest. NameFinderTest contains tests to find a name from a list when it exists and does not exist. ShopTest contains tests to view a product by id when it exists and does not exist. CustomerTest contains tests to calculate membership fees for customers with different membership levels (Normal, Gold, Platinum).

Uploaded by

Vamsi Gembali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views3 pages

Hands On - JUNIT

The document contains test cases for three different Java classes - NameFinderTest, ShopTest, and CustomerTest. NameFinderTest contains tests to find a name from a list when it exists and does not exist. ShopTest contains tests to view a product by id when it exists and does not exist. CustomerTest contains tests to calculate membership fees for customers with different membership levels (Normal, Gold, Platinum).

Uploaded by

Vamsi Gembali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name Finder App:-

import java.util.*;

import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

public class NameFinderTest {

static List<String> namelist = new ArrayList<String>();


static NameFinder nameFinder = null;

@BeforeClass
public static void setUp(){

namelist.add("Arun");
namelist.add("Ashwin");
namelist.add("Anil");
namelist.add("Akash");
namelist.add("Azhar");

nameFinder=new NameFinder();
}
@Test

public void test11FindNameWhenExists() throws NameNotFoundException {


assertTrue(nameFinder.findName(namelist,"Arun"));
}
@Test(expected=NameNotFoundException.class)
public void test12FindNameWhenNotExists() throws NameNotFoundException {
assertFalse(nameFinder.findName(namelist,"adarsh"));
}

-----------------------------------------------------------------------------------
--------------------------------------
Search Product By Id:-

import java.util.*;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

public class ShopTest {

static List<Product> productList = new ArrayList<>();


static Shop s = null;
static Product p1,p2,p5;

@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.*;

public class CustomerTest {

@BeforeClass
public static void setUp() throws Exception {

@AfterClass
public static void tearDown() throws Exception {

}
@Test
public void testCollectMembershipFeesForNormal(){

Customer c=new Customer(1,"adarsh","987","Normal");


assertEquals(0,c.collectMembershipFees(),0.001);
}
@Test
public void testCollectMembershipFeesForGold() {

Customer c=new Customer(1,"adarsh","987","Gold");


assertEquals(75000,c.collectMembershipFees(),0.001);

}
@Test
public void testCollectMembershipFeesForPlatinum() {
Customer c=new Customer(1,"adarsh","733","Platinum");
assertEquals(125000,c.collectMembershipFees(),0.001);
}
}

-----------------------------------------------------
*----------------------------------------------------------------

You might also like