-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created JUnit tests for Day007.class
- Loading branch information
1 parent
7ffef63
commit 0b189bc
Showing
3 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
days/day007/src/main/java/com/thegreatapi/ahundreddaysofjava/day007/Day007.java
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
days/day007/src/test/java/com/thegreatapi/ahundreddaysofjava/day007/Day007Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.thegreatapi.ahundreddaysofjava.day007; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
import java.text.MessageFormat; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import org.junit.jupiter.api.AfterEach; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class Day007Test { | ||
|
||
private final PrintStream standardOut = System.out; | ||
private final ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream(); | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
System.setOut(new PrintStream(outputStreamCaptor)); | ||
} | ||
|
||
@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); | ||
//assertEquals(expectedMessage, outputStreamCaptor.toString().trim()); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
System.setOut(standardOut); | ||
} | ||
} |