Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#Marshinin Arsenii

# Java Junior Developer Training Course.
88 hours training + 32 hours work project = 120 hr.

Expand Down
24 changes: 22 additions & 2 deletions src/main/java/com/acme/edu/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/acme/edu/Printer.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
17 changes: 9 additions & 8 deletions src/test/java/com/acme/edu/iteration01/LoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -109,5 +111,4 @@ public void shouldLogReference() throws IOException {
//endregion
}

*/
}