diff --git a/README.md b/README.md index dbbdfc720..529e608d6 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +#Marshinin Arsenii + # Java Junior Developer Training Course. 88 hours training + 32 hours work project = 120 hr. diff --git a/src/main/java/com/acme/edu/Logger.java b/src/main/java/com/acme/edu/Logger.java index f0b274045..8717abbb5 100644 --- a/src/main/java/com/acme/edu/Logger.java +++ b/src/main/java/com/acme/edu/Logger.java @@ -2,10 +2,30 @@ public class Logger { public static void log(int message) { - System.out.println("primitive: " + message); + Printer printer = new Printer("primitive: ", message); + printer.print(); } public static void log(byte message) { - System.out.println("primitive: " + message); + Printer printer = new Printer("primitive: ", message); + printer.print(); + } + + public static void log(char ch) { + System.out.println("char: " + ch); + } + + public static void log(String s) { + System.out.println("string: " + s); + } + + public static void log(boolean message) { + Printer printer = new Printer("primitive: ", message); + printer.print(); + } + + public static void log(Object message) { + Printer printer= new Printer("reference: ", message); + printer.print(); } } diff --git a/src/main/java/com/acme/edu/Printer.java b/src/main/java/com/acme/edu/Printer.java new file mode 100644 index 000000000..438dbf01f --- /dev/null +++ b/src/main/java/com/acme/edu/Printer.java @@ -0,0 +1,27 @@ +package com.acme.edu; + +public class Printer { + private final String prefix; + private final String message; + + public Printer(String prefix, String message) { + this.prefix = prefix; + this.message = message; + } + + public Printer(String prefix, int message) { + this(prefix, "" + message); + } + + public Printer(String prefix, boolean message) { + this(prefix, "" + message); + } + + public Printer(String prefix, Object message) { + this(prefix, message.toString()); + } + + public void print() { + System.out.println(prefix + message); + } +} diff --git a/src/test/java/com/acme/edu/iteration01/LoggerTest.java b/src/test/java/com/acme/edu/iteration01/LoggerTest.java index b9bacdb90..c123ef4be 100644 --- a/src/test/java/com/acme/edu/iteration01/LoggerTest.java +++ b/src/test/java/com/acme/edu/iteration01/LoggerTest.java @@ -9,6 +9,9 @@ import java.io.*; public class LoggerTest implements SysoutCaptureAndAssertionAbility { + + private final String sep = System.lineSeparator(); + //region given @Before public void setUpSystemOut() throws IOException { @@ -32,16 +35,18 @@ public void shouldLogInteger() throws IOException { //region then assertSysoutContains("primitive: "); - assertSysoutEquals("primitive: 1\nprimitive: 0\nprimitive: -1\n"); + assertSysoutEquals("primitive: 1" + sep + + "primitive: 0" + sep + + "primitive: -1" + sep); //endregion } @Test public void shouldLogByte() throws IOException { //region when - Logger.log((byte)1); - Logger.log((byte)0); - Logger.log((byte)-1); + Logger.log((byte) 1); + Logger.log((byte) 0); + Logger.log((byte) -1); //endregion //region then @@ -52,9 +57,6 @@ public void shouldLogByte() throws IOException { //endregion } - /* - TODO: implement Logger solution to match specification as tests - @Test public void shouldLogChar() throws IOException { //region when @@ -109,5 +111,4 @@ public void shouldLogReference() throws IOException { //endregion } - */ } \ No newline at end of file