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

Add JUnit test for Day007.class #181

Open
wants to merge 26 commits into
base: main
Choose a base branch
from

Conversation

Viniberaldo
Copy link
Contributor

This pull request introduces a new JUnit test class (Day007Test.java) to verify the functionality of the Day007 class.

Key changes:

  • Created Day007Test.java in src/test/java/com/thegreatapi/ahundreddaysofjava/day007
  • Changed the visibility of the showMessage method in the Day007 class, from private to public
  • Added a single test method "shouldFormatMessageCorrectly()" to test the showMessage() method
  • Implemented the test using JUnit 5 and AssertJ for more readable assertions

The test verifies that the showMessage() method correctly formats the message using MessageFormat.

Benefits:

  • Ensures proper formatting of the message
  • Provides confidence in the correctness of the showMessage() method

Please review the test implementation and provide feedback if needed.

@Viniberaldo
Copy link
Contributor Author

Hi @hbelmiro, I'm quoting you to see my pull request 😄

Copy link
Owner

@hbelmiro hbelmiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution @Viniberaldo.
The idea is to replace the existing code with tests. So, you need to move the example to the test and remove the original class.
Also, since we'll use tests, we can change the example to not print the formatted message. In the original code, I've printed it to the console so people can see the result. Now that we'll have a test, the test itself is the verification. So all the boilerplate you had to add to verify the output can be removed.
See what I did here, for example: https://github.com/hbelmiro/100DaysOfJava/pull/62/files

days/day007/pom.xml Outdated Show resolved Hide resolved
days/day007/pom.xml Outdated Show resolved Hide resolved
days/day007/pom.xml Outdated Show resolved Hide resolved
Copy link
Owner

@hbelmiro hbelmiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Viniberaldo. Looks way better now.
I left a few more comments.

… and removes the Day007 class and its directory.

Key changes:

Created Day007Test.java in src/test/java/com/thegreatapi/ahundreddaysofjava/day007
Removed the Day007 class and its directory
Added a single test method "shouldFormatMessageCorrectly()" to test the showMessage() method
Implemented the test using JUnit 5 and AssertJ for more readable assertions
The test verifies that the showMessage() method correctly formats the message using MessageFormat.

Benefits:

Ensures proper formatting of the message
Provides confidence in the correctness of the showMessage() method

Please review the test implementation and provide feedback if needed.
… and removes the Day007 class and its directory.

    Key changes:

    Created Day007Test.java in src/test/java/com/thegreatapi/ahundreddaysofjava/day007
    Removed the Day007 class and its directory
    Added a single test method "shouldFormatMessageCorrectly()" to test the showMessage() method
    Implemented the test using JUnit 5 and AssertJ for more readable assertions
    The test verifies that the showMessage() method correctly formats the message using MessageFormat.

    Benefits:

    Ensures proper formatting of the message
    Provides confidence in the correctness of the showMessage() method

    Please review the test implementation and provide feedback if needed.
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.

2 participants