Skip to content

Commit

Permalink
Converted Day 007 to test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Viniberaldo authored Oct 7, 2024
1 parent 5e67b52 commit 0bbaa2f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
14 changes: 12 additions & 2 deletions days/day007/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>day007</artifactId>


<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.thegreatapi.ahundreddaysofjava.day007;

import java.text.MessageFormat;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;

class Day007Test {

@Test
void shouldFormatMessageCorrectly() {
// Arrange
String param1 = "Hello";
String param2 = "World";
String param3 = "Java";

// Act
String actualMessage = MessageFormat.format(
"This message contains 3 parameters. The #1 is ''{0}'', "
+ "the #2 is ''{1}'', and the #3 is ''{2}''.",
param1, param2, param3);

// Assert
String expectedMessage = "This message contains 3 parameters. The #1 is"
+ " 'Hello', the #2 is 'World', and the #3 is 'Java'.";
assertThat(actualMessage).isEqualTo(expectedMessage);
}

}

0 comments on commit 0bbaa2f

Please sign in to comment.