Skip to content

LuggageSlipTest Documentation

Hailey Fritz edited this page Nov 23, 2023 · 8 revisions

Overview

The LuggageSlipTest class is a test class for the Passenger class, using the JUnit frameworks for testing.

Class-Level

  • The LuggageSlipTest class is called via the Test Suite Class Test Suite and therefore requires no individual instance for the required functionality. The below code showcases how the LuggageSlip class is referenced and utilized:
@RunWith(Suite.class)
@Suite.SuiteClasses({
      LuggageManagementSystemTest.class,
      PassengerTest.class,
      LuggageSlipTest.class,
      LuggageManifestTest.class,
      FlightTest.class
})
  • This class is used with the Template design pattern as a subclass of the TestTemplate class.

  • The main methods implemented are as follows:

    • testPassengerField()

    • luggageSlipIDCounterField()

    • luggageSlipIDField()

    • labelField()

    • hasOwnerTest()

    • testConstructor()

    • testOverloadedConstructor()

    • testToString()

These methods are used to test method & attribute naming conventions and types, behaviour and functionality of methods, expected abstractions and inheritance hierarchies of the student's submitted LuggageSlip.java file.

Method-Level

Methods

The below methods are used to test the naming conventions and functionality of the student's submitted LuggageSlip class. For each method there is no returned object nor any accepted parameters, however, the use of inherited attributes from the parent class, TestTemplate is used to track its grading, i.e.

  • boolean passed is used to indicate whether a particular test condition is true and therefore the designated mark should be awarded.
  • Class<?> testClass is used to set the class type to LuggageSlip to indicate the LuggageSlip class is being tested.

Note: The inherited attribute int passedTestMarks is decremented for each test that fails, thereby determining the mark to be awarded for the "Passes JUnit Tests" section. A Feedback object is created at the end of each test, reflecting the appropriate feedback response and mark to be displayed from the test result.


  • public LuggageSlipTest(): The LuggageSlipTest constructor create objects passenger of type Passenger, flight of type Flight and luggageSlip and luggageSlip1 of type LuggageSlip for use in the testing of the LuggageSlip class.

    The Class<?> testClass attribute is initialized to LuggageSlip.class, indicating that the class currently being tested is the LuggageSlip class. The String className attribute is initialized to "LuggageSlip", indicating to the created Feedback objects that the feedback belongs to the LuggageSlip class.


  • @Before public void init(): This method reinitializes the requisite variables before each test annotated with @Test
response = "";
mark = 0;
declaredOnly = false;
passed = false;
field = null;

  • @Test public void testPassengerField(): This method is used to test the use of proper naming convention and type (Passenger) of the owner field in the student LuggageSlip class.

  • @Test public void luggageSlipIDCounterField(): This method is used to test the use of proper naming convention and type (int) of the luggageSlipIDCounter field in the student LuggageSlip class.

  • @Test public void luggageSlipIDField(): This method is used to test the use of proper naming convention and type (String) of the luggageSlipID field in the student LuggageSlip class.

  • @Test public void labelField(): This method is used to test the use of proper naming convention and type (String) of the label field in the student LuggageSlip class.

  • @Test public void testConstructor(): Asserts that the created LuggageSlip object's attributes is correctly initialized with the provided Passenger and Flight parameter objects. An assertion on the label attribute is made to ensure it is set to an empty String ("").

  • @Test public void testOverloadedConstructor(): Asserts that the created LuggageSlip object's attributes is correctly initialized with the provided Passenger and Flight parameter objects. An assertion on the label attribute is made to ensure it is set to the excess luggage cost.

  • @Test public void hasOwner(): Asserts that the submitted method accurately validates whether the provided passenger passport number is the same as the passport number of the owner attribute on the LuggageSlip object.

  • @Test public void testToString(): Asserts that the returned String accurately represents the LuggageSlip object.

  • private void checkSet(Object expectedValue, Object thisClass): This method is a helper method which retrieves the current value stored in the field variable once it is not null. This is done by making the field accessible and calling the field.get() method on the class it needs the value from and storing it in an Object variable called value.

    If the value is null, this indicates that that the field being checked is not set to any value or does not exist. If the value is unequal to the expected value, this indicates the field being checked was not initialized with the value from the constructor. An appropriate response is added for each case.

Field-Level

Fields

  • private Flight flight: An initialized Flight attribute used to test the accuracy of the LuggageSlip class functionality in relation to the Flight class.

  • private LuggageSlip luggageSlip: An initialized LuggageSlip attribute used to test the accuracy of the LuggageSlip class functionality.

  • private LuggageSlip luggageSlip1: An initialized LuggageSlip attribute used to test the accuracy of the LuggageSlip class functionality.

Clone this wiki locally