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

Added unit tests for MicroSwitchController class #304

Closed
wants to merge 1 commit into from

Conversation

avaenk
Copy link
Collaborator

@avaenk avaenk commented Feb 2, 2025

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

Screenshot 2025-02-02 at 1 55 56 PM

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

Copy link
Collaborator

@Ed0827 Ed0827 left a 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) {
Copy link
Collaborator

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);
Copy link
Collaborator

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.

Copy link
Collaborator

@yrlmanoharreddy yrlmanoharreddy left a 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.

@avaenk avaenk closed this Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Write Unit Tests for MicroSwitchHelper Class
4 participants