Class CalculatorTest

java.lang.Object
test.CalculatorTest

public class CalculatorTest extends Object
Provides test cases for the Calculator class.

Tests the shipping cost calculation for parcels based on the defined default shipping rules. Ensures that the correct shipping cost is calculated for parcels of different sizes and weights and that exceptions are thrown for oversized parcels and parcels with invalid dimensions or weight.

Contains the following test cases:

See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Tests that a parcel with no dimension throws an IllegalArgumentException.
    void
    Tests that a parcel exceeding the maximum dimensions of 120x60x60 cm throws an IllegalArgumentException.
    void
    Tests that a parcel exceeding the girth limit is priced correctly.
    void
    Tests that a parcel exceeding the maximum weight of 31 kg throws an IllegalArgumentException.
    void
    Tests calculation precision for a weight that is very close to 10 kg boundary.
    void
    Tests that a large parcel with dimensions up to 120x60x60 cm, a girth of up to 300 cm, and a weight up to 5 kg is correctly calculated to cost 5.89 EUR.
    void
    Tests that a parcel with maximum integer dimensions and weight does not crash the program.
    void
    Tests that a medium parcel with dimensions up to 60x30x15 cm and up to 2 kg is correctly calculated to cost 4.39 EUR.
    void
    Tests a parcel with near-limit dimensions and weight to ensure correct rule selection.
    void
    Tests that a parcel with negative dimensions throws an IllegalArgumentException.
    void
    Tests that a parcel with negative weight throws an IllegalArgumentException.
    void
    Tests that a Null parcel throws an IllegalArgumentException.
    void
    Tests that a parcel with only one null dimension throws an IllegalArgumentException.
    void
    Tests that a parcel that has to be rotated to fit the dimensions is priced correctly.
    void
    Tests that small heavy parcel is priced correctly.
    void
    Tests that a small parcel with dimensions up to 30x30x15 cm and up to 1 kg is correctly calculated to cost 3.89 EUR.
    void
    Tests that an extra-large parcel with dimensions up to 120x60x60 cm, a girth of up to 300 cm, and a weight up to 10 kg is correctly calculated to cost 7.99 EUR.
    void
    Tests that an extra-extra-large parcel with dimensions up to 120x60x60 cm and a weight up to 31 kg is correctly calculated to cost 14.99 EUR.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CalculatorTest

      public CalculatorTest()
  • Method Details

    • testSmallParcelRate

      @Test public void testSmallParcelRate() throws ShippingRuleException
      Tests that a small parcel with dimensions up to 30x30x15 cm and up to 1 kg is correctly calculated to cost 3.89 EUR.
      Throws:
      ShippingRuleException
    • testMediumParcelRate

      @Test public void testMediumParcelRate() throws ShippingRuleException
      Tests that a medium parcel with dimensions up to 60x30x15 cm and up to 2 kg is correctly calculated to cost 4.39 EUR.
      Throws:
      ShippingRuleException
    • testLargeParcelRate

      @Test public void testLargeParcelRate() throws ShippingRuleException
      Tests that a large parcel with dimensions up to 120x60x60 cm, a girth of up to 300 cm, and a weight up to 5 kg is correctly calculated to cost 5.89 EUR.
      Throws:
      ShippingRuleException
    • testXLParcelRate

      @Test public void testXLParcelRate() throws ShippingRuleException
      Tests that an extra-large parcel with dimensions up to 120x60x60 cm, a girth of up to 300 cm, and a weight up to 10 kg is correctly calculated to cost 7.99 EUR.
      Throws:
      ShippingRuleException
    • testXXLParcelRate

      @Test public void testXXLParcelRate() throws ShippingRuleException
      Tests that an extra-extra-large parcel with dimensions up to 120x60x60 cm and a weight up to 31 kg is correctly calculated to cost 14.99 EUR.
      Throws:
      ShippingRuleException
    • testRotatedParcelRate

      @Test public void testRotatedParcelRate() throws ShippingRuleException
      Tests that a parcel that has to be rotated to fit the dimensions is priced correctly.
      Throws:
      ShippingRuleException
    • testSmallHeavyParcelRate

      @Test public void testSmallHeavyParcelRate() throws ShippingRuleException
      Tests that small heavy parcel is priced correctly.
      Throws:
      ShippingRuleException
    • testExceedMaxWeight

      @Test public void testExceedMaxWeight()
      Tests that a parcel exceeding the maximum weight of 31 kg throws an IllegalArgumentException.
    • testExceedMaxDimensions

      @Test public void testExceedMaxDimensions()
      Tests that a parcel exceeding the maximum dimensions of 120x60x60 cm throws an IllegalArgumentException.
    • testAllZeroDimensions

      @Test public void testAllZeroDimensions()
      Tests that a parcel with no dimension throws an IllegalArgumentException.
    • testOneZeroDimension

      @Test public void testOneZeroDimension()
      Tests that a parcel with only one null dimension throws an IllegalArgumentException.
    • testNegativeDimensions

      @Test public void testNegativeDimensions()
      Tests that a parcel with negative dimensions throws an IllegalArgumentException.
    • testNegativeWeight

      @Test public void testNegativeWeight()
      Tests that a parcel with negative weight throws an IllegalArgumentException.
    • testNullPacket

      @Test public void testNullPacket()
      Tests that a Null parcel throws an IllegalArgumentException.
    • testExceedMaxGirth

      @Test public void testExceedMaxGirth() throws ShippingRuleException
      Tests that a parcel exceeding the girth limit is priced correctly.
      Throws:
      ShippingRuleException
    • testFloatingPointPrecisionForWeight

      @Test public void testFloatingPointPrecisionForWeight() throws ShippingRuleException
      Tests calculation precision for a weight that is very close to 10 kg boundary.
      Throws:
      ShippingRuleException
    • testNearLimitCombination

      @Test public void testNearLimitCombination() throws ShippingRuleException
      Tests a parcel with near-limit dimensions and weight to ensure correct rule selection.
      Throws:
      ShippingRuleException
    • testMaxIntegerDimensions

      @Test public void testMaxIntegerDimensions()
      Tests that a parcel with maximum integer dimensions and weight does not crash the program.