Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write Unit Tests for TiltSwitchHelper Class #301

Closed
5 tasks done
yrlmanoharreddy opened this issue Jan 26, 2025 · 0 comments · Fixed by #305
Closed
5 tasks done

Write Unit Tests for TiltSwitchHelper Class #301

yrlmanoharreddy opened this issue Jan 26, 2025 · 0 comments · Fixed by #305
Assignees
Labels
iteration-starter A task to help team members kick off a sprint. unit-test To ensure individual components or functions work as intended.

Comments

@yrlmanoharreddy
Copy link
Collaborator

yrlmanoharreddy commented Jan 26, 2025

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:

  1. Test Initialization Logic:
    Verify that the isTilted field is correctly initialized based on the initial state of the DigitalInput object passed to the constructor.

  2. 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.

  3. 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).

  4. Test Logging:
    Verify that the initialize method logs the expected message ("Initializing Tilt Switch").

  5. Mocking Dependencies:
    Use a mocking framework (e.g., Mockito) to mock the DigitalInput and DigitalStateChangeListener dependencies.

  6. 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

  • All test cases outlined in the tasks above are implemented.
  • Code coverage for the TiltSwitchHelper class is at least 70%.
  • Tests are written using a Java JUnit testing framework
  • Mocking is implemented using a framework such as Mockito or a similar tool.
  • All tests pass successfully, and edge cases are handled gracefully.
@yrlmanoharreddy yrlmanoharreddy added iteration-starter A task to help team members kick off a sprint. unit-test To ensure individual components or functions work as intended. labels Jan 26, 2025
@yrlmanoharreddy yrlmanoharreddy changed the title Add Unit Tests for TiltSwitchHelper Class Write Unit Tests for TiltSwitchHelper Class Jan 26, 2025
@RalphTan37 RalphTan37 self-assigned this Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iteration-starter A task to help team members kick off a sprint. unit-test To ensure individual components or functions work as intended.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants