Package info.walnutstreet.vs.junit.ps03

Source Code of info.walnutstreet.vs.junit.ps03.TestGoodModel

/**
*
*/
package info.walnutstreet.vs.junit.ps03;

import info.walnutstreet.vs.ps03.dbserver.GoodModel;
import info.walnutstreet.vs.ps03.exceptions.InvalidAvaiableNumberException;
import info.walnutstreet.vs.ps03.exceptions.InvalidPriceException;
import info.walnutstreet.vs.ps03.exceptions.InvalidUniqueIdException;

import java.rmi.RemoteException;

import junit.framework.TestCase;

/**
* @author Christoph Gostner
* @version 0.1
*
*/
public class TestGoodModel extends TestCase {

  public void testFirstGood() throws RemoteException {
    /*
     * Test invalid use of constructor #1
     */
    try {
      new GoodModel(-1, null);
      assertTrue(false);
    } catch (InvalidUniqueIdException e) {
      assertTrue(true);
    }
   
    /*
     * Test invalid use of constructor #2
     */
    try {
      new GoodModel(0, null);
      assertTrue(false);
    } catch (InvalidUniqueIdException e) {
      assertTrue(true);
    }
   
    /*
     * Test default constructor
     */
    try {
      new GoodModel();
      assertTrue(true);
    } catch (InvalidUniqueIdException e) {
      assertTrue(false);
    }
  }
 
  public void testSecondGood() throws RemoteException {
    /*
     * Test construction of a good object #1
     */
    try {
      GoodModel goodModel = new GoodModel();
      goodModel.setId(1);
      goodModel.setName("Article #1");
      goodModel.setAvailable(10);
      goodModel.setDescription("Bla");
      goodModel.setPrice(10.0);
     
      assertTrue(true);
    } catch (InvalidUniqueIdException e) {
      assertTrue(false);
    } catch (InvalidAvaiableNumberException e) {
      assertTrue(false);
    } catch (InvalidPriceException e) {
      assertTrue(false);
    }
   
    /*
     * Test construction of a good object #2
     */
    try {
      GoodModel goodModel = new GoodModel(2, "Article #2");
      goodModel.setAvailable(10);
      goodModel.setDescription("Bla");
      goodModel.setPrice(10.0);
     
      assertTrue(true);
    } catch (InvalidUniqueIdException e) {
      assertTrue(false);
    } catch (InvalidAvaiableNumberException e) {
      assertTrue(false);
    } catch (InvalidPriceException e) {
      assertTrue(false);
    }
  }
 
  public void testGoodInvalidId() throws RemoteException {
    /* test constructor with invalid id */
    try {
      new GoodModel(0, "Invalid good");
      assertTrue(false);
    } catch (InvalidUniqueIdException e) {
      assertTrue(true);
    }
   
    /* test good with invalid id */
    try {
      GoodModel goodModel = new GoodModel();
      goodModel.setId(-3324);
      assertTrue(false);
    } catch (InvalidUniqueIdException e) {
      assertTrue(true);
    }
  }
 
  public void testGoodInvalidAvaiableNumber() throws RemoteException {
    /* test invalid number of avaiable goods #1 */
    try {
      GoodModel goodModel = new GoodModel();
      goodModel.setAvailable(10);
     
      assertTrue(true);
    } catch (InvalidUniqueIdException e) {
      assertTrue(false);
    } catch (InvalidAvaiableNumberException e) {
      assertTrue(false);
    }
   
    /* test invalid number of avaiable goods #2 */
    try {
      GoodModel goodModel = new GoodModel();
      goodModel.setAvailable(0);
     
      assertTrue(true);
    } catch (InvalidUniqueIdException e) {
      assertTrue(false);
    } catch (InvalidAvaiableNumberException e) {
      assertTrue(false);
    }
   
    /* test invalid number of avaiable goods #3 */
    try {
      GoodModel goodModel = new GoodModel();
      goodModel.setAvailable(-10);
     
      assertTrue(false);
    } catch (InvalidUniqueIdException e) {
      assertTrue(false);
    } catch (InvalidAvaiableNumberException e) {
      assertTrue(true);
    }
  }
 
  public void testGoodWithInvalidPrice() throws InvalidUniqueIdException, RemoteException {
    try {
      GoodModel goodModel = new GoodModel();
      goodModel.setPrice(10.0);
     
      assertTrue(true);
    } catch (InvalidPriceException e) {
      assertTrue(false);
    }
   
    try {
      GoodModel goodModel = new GoodModel();
      goodModel.setPrice(0.0);
     
      assertTrue(true);
    } catch (InvalidPriceException e) {
      assertTrue(false);
    }
   
    try {
      GoodModel goodModel = new GoodModel();
      goodModel.setPrice(-10.0);
     
      assertTrue(false);
    } catch (InvalidPriceException e) {
      assertTrue(true);
    }
  }
}
TOP

Related Classes of info.walnutstreet.vs.junit.ps03.TestGoodModel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.