Write Unit Tests for TiltSwitchHelper Class #301
Labels
iteration-starter
A task to help team members kick off a sprint.
unit-test
To ensure individual components or functions work as intended.
Description:
The TiltSwitchHelper class manages the state of a tilt switch using Pi4J's DigitalInput and event listeners. We need to write unit tests to ensure that its behavior is correct and reliable, particularly regarding event listener management and state updates.
Tasks:
Test Initialization Logic:
Verify that the isTilted field is correctly initialized based on the initial state of the DigitalInput object passed to the constructor.
Test Event Listener Management:
Confirm that listeners are properly added using the addEventListener method.
Ensure that the correct listener is invoked when the state of the tilt switch changes.
Validate that listeners are removed using the removeEventListener method, and that the listener is set to null afterward.
Test State Update:
Verify that the isTilted field accurately reflects the tilt switch's state after it changes.
Ensure that the state of the isTilted field is updated when the listener is triggered (i.e., when the tilt switch's state changes).
Test Logging:
Verify that the initialize method logs the expected message ("Initializing Tilt Switch").
Mocking Dependencies:
Use a mocking framework (e.g., Mockito) to mock the DigitalInput and DigitalStateChangeListener dependencies.
Edge Cases:
Test the behavior when no event listener is attached but the state of the tilt switch changes.
Ensure that removeEventListener behaves correctly when no listener has been added.
Acceptance Criteria
The text was updated successfully, but these errors were encountered: