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 PIRSensorHelper #309

Open
5 tasks
yrlmanoharreddy opened this issue Feb 10, 2025 · 0 comments · May be fixed by #312
Open
5 tasks

Write Unit Tests for PIRSensorHelper #309

yrlmanoharreddy opened this issue Feb 10, 2025 · 0 comments · May be fixed by #312
Assignees
Labels
enhancement New feature or request unit-test To ensure individual components or functions work as intended.

Comments

@yrlmanoharreddy
Copy link
Collaborator

Description:
The PIRSensorHelper class manages a PIR motion sensor using Pi4J's DigitalInput. Unit tests are required to validate its behavior, including motion detection, event listener management, and initialization.

Developer Notes:

  1. Test Initialization Logic:

Verify that isMoving is correctly initialized based on pirSensorInput.isHigh().
Ensure that the initialize method adds an event listener to pirSensorInput.

  1. Test Motion Detection (initialize Method):

Simulate a change in pirSensorInput state and check if isMoving updates correctly.

  1. Test Event Listener Management:

Validate that addEventListener correctly adds an event listener to pirSensorInput.
Ensure removeEventListener removes the listener and sets pirSensorInputListener to null.
Check that multiple calls to removeEventListener do not cause errors.

  1. Mocking Dependencies:

Use Mockito to mock DigitalInput and DigitalStateChangeListener.
Ensure tests do not require real hardware.

  1. Edge Cases:

Verify behavior when pirSensorInput is initially low.
Ensure addEventListener correctly overrides existing listeners.
Test that removeEventListener does not fail when no listener is present.

Acceptance Criteria

  • All test cases outlined in the tasks above are implemented.

  • Code coverage for the MicroSwitchHelper 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 the enhancement New feature or request label Feb 10, 2025
@yrlmanoharreddy yrlmanoharreddy added the unit-test To ensure individual components or functions work as intended. label Feb 10, 2025
@Ed0827 Ed0827 self-assigned this Feb 10, 2025
@Ed0827 Ed0827 linked a pull request Feb 15, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request unit-test To ensure individual components or functions work as intended.
Projects
Status: 🆕 New
Development

Successfully merging a pull request may close this issue.

2 participants