-
Notifications
You must be signed in to change notification settings - Fork 7
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
Added unit tests for MicroSwitchController class #304
Conversation
Ava seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functionalities provided in the helper are well organized and utilized effectively. Great job!
@@ -64,4 +64,9 @@ public void removeEventListener() | |||
microSwitchInputListener = null; | |||
} | |||
} | |||
|
|||
public void setLog(Logger log) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on this! This will help when troubleshooting your code by setting up a logger.
@@ -10,7 +10,7 @@ | |||
*/ | |||
public class MicroSwitchHelper { | |||
|
|||
private static final Logger log = LoggerFactory.getLogger(MicroSwitchHelper.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This provides flexibility to modify logger messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close this pull request.
Fixes #302
Description:
Adds unit tests for the MicroSwitchHelper using JUnit 5 and Mockito, checking its initialization, state updates and event listener management. Also introduces logger injection to confirm the correct log message ('Initializing Micro Switch') is being produced.
What was changed:
In MicroSwitchHelper the logger was converted from static final to static with a new setLog(Logger newLog) method, this enables the use of a custom logger for testing.
Unit tests were implemented to verify initialization logic, state updates, and event listener management, and tests to confirm the expected log message.
How it was changed:
The logger in MicroSwitchHelper was changed from a static final to an instance level with the new setLog method. Unit tests were implemented using JUnit 5 and Mockito in order to simulate different kinds of digital input and to verify specific fields are correct upon initialization. Verified the initial listener in the initialize methods updates isPressed state correctly when the input state is changed. New tests to confirm that the add and remove event listener methods work correctly. New logging tests to check that the expected log messa