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 TouchSwitchHelper #298

Open
5 tasks
yrlmanoharreddy opened this issue Jan 13, 2025 · 1 comment
Open
5 tasks

Write Unit Tests for TouchSwitchHelper #298

yrlmanoharreddy opened this issue Jan 13, 2025 · 1 comment
Labels
good-first-issue Good for newcomers unit-test To ensure individual components or functions work as intended.

Comments

@yrlmanoharreddy
Copy link
Collaborator

Description:
The TouchSwitchHelper class manages the interaction with a touch switch connected via a Pi4J DigitalInput. This issue involves writing unit tests to verify the functionality and robustness of the TouchSwitchHelper class.

Tasks:

  1. Test Initialization Logic

    • Verify that the isTouched property correctly reflects the initial state of the DigitalInput.
    • Ensure that the initialize() method is called during object instantiation.
  2. Test Event Listener Management

    • Test if the default DigitalStateChangeListener updates the isTouched property correctly when the state of the DigitalInput changes.
    • Validate that addEventListener() correctly adds a custom listener to the DigitalInput.
    • Test that removeEventListener() properly removes the listener and ensures no state updates occur after removal.
  3. Test Logging

    • Verify that appropriate logs are generated during the initialization process.
  4. Mock Dependencies

    • Use a mock for DigitalInput to simulate state changes and interactions.
    • Use a mock for DigitalStateChangeListener to validate listener behavior.
  5. Edge Cases

    • Test the behavior when no listeners are added or removed.
    • Validate that the removeEventListener() method is idempotent (can be called multiple times without error).

Acceptance Criteria

  • All test cases outlined in the tasks above are implemented.
  • Code coverage for the TouchSwitchHelper 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 enhancement New feature or request good-first-issue Good for newcomers unit-test To ensure individual components or functions work as intended. labels Jan 13, 2025
@yrlmanoharreddy yrlmanoharreddy removed the enhancement New feature or request label Jan 26, 2025
@pranayh24
Copy link

Hi, I'd like to work on this issue. Could you assign it to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good-first-issue Good for newcomers unit-test To ensure individual components or functions work as intended.
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants