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 Link icon

    Constructors
    Constructor
    Description
     
  • Method Summary Link icon

    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 Link icon

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

    • CalculatorTest Link icon

      public CalculatorTest()
  • Method Details Link icon

    • testSmallParcelRate Link icon

      @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 Link icon

      @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 Link icon

      @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 Link icon

      @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 Link icon

      @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 Link icon

      @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 Link icon

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

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

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

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

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

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

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

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

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

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

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

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