-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
72 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ru.j4j.inheritance; | ||
|
||
public class HtmlReport extends TextReport { | ||
public String generate(String name, String body) { | ||
return "<h1>" + name + "</h1>" | ||
+ "<br/>" | ||
+ "<span>" + body + "</span>"; | ||
} | ||
} |
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,11 @@ | ||
package ru.j4j.inheritance; | ||
|
||
public class JSONReport { | ||
public String generate(String name, String body) { | ||
String ln = System.lineSeparator(); | ||
return String.format("{" + ln | ||
+ "\t\"name\" : \"%s\"," + ln | ||
+ "\t\"body\" : \"%s\"" + ln | ||
+ "}", name, body); | ||
} | ||
} |
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,11 @@ | ||
package ru.j4j.inheritance; | ||
|
||
public class ReportUsage { | ||
public static void main(String[] args) { | ||
TextReport textReport = new TextReport(); | ||
HtmlReport htmlReport = new HtmlReport(); | ||
System.out.println(textReport.generate("Report's name", "Report's body")); | ||
System.out.println(htmlReport.generate("Report's name", "Report's body")); | ||
|
||
} | ||
} |
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,7 @@ | ||
package ru.j4j.inheritance; | ||
|
||
public class TextReport { | ||
public String generate(String name, String body) { | ||
return name + System.lineSeparator() + body; | ||
} | ||
} |
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,34 @@ | ||
package ru.j4j.inheritance; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class JSONReportTest { | ||
@Test | ||
public void whenTestGenerateMethod() { | ||
String ln = System.lineSeparator(); | ||
String expected = "{" + ln | ||
+ "\t\"name\" : \"Report's name\"," + ln | ||
+ "\t\"body\" : \"Report's body\"" + ln | ||
+ "}"; | ||
String name = "Report's name"; | ||
String body = "Report's body"; | ||
String result = new JSONReport().generate(name, body); | ||
assertThat(result).isEqualTo(expected); | ||
} | ||
|
||
@Test | ||
public void whenNameIsDavidBodyIsNameSong() { | ||
String ln = System.lineSeparator(); | ||
String expected = "{" + ln | ||
+ "\t\"name\" : \"David Gilmour\"," + ln | ||
+ "\t\"body\" : \"Shine On You Crazy Diamond\"" + ln | ||
+ "}"; | ||
String name = "David Gilmour"; | ||
String body = "Shine On You Crazy Diamond"; | ||
String result = new JSONReport().generate(name, body); | ||
assertThat(result).isEqualTo(expected); | ||
} | ||
|
||
|
||
} |