package com.diogonunes.jcdp.unit;

import com.diogonunes.jcdp.bw.Printer;
import com.diogonunes.jcdp.bw.api.IPrinter;
import com.diogonunes.jcdp.bw.impl.TerminalPrinter;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class PrinterBuilderTests {

    @Test
    public void Printer_Creation_BuilderExists() {
        // ARRANGE

        // ACT
        Printer.Builder printerBuilder = new Printer.Builder(Printer.Types.TERM);

        // ASSERT
        assertThat(printerBuilder, not(equalTo(null)));
        assertThat(printerBuilder, instanceOf(Printer.Builder.class));
    }

    @Test
    public void Printer_Creation_BuilderReturnsTerminalPrinter() {
        // ARRANGE
        Printer.Builder b = new Printer.Builder(Printer.Types.TERM);

        // ACT
        IPrinter printer = b.build();

        // ASSERT
        assertThat(printer, not(equalTo(null)));
        assertThat(printer, instanceOf(Printer.class));
        assertThat("Implementation is TerminalPrinter", printer.toString(), containsString(TerminalPrinter.class.getSimpleName()));
    }

    @Test
    public void Printer_Creation_BuilderHandlesLevel() {
        // ARRANGE
        Printer.Builder b = new Printer.Builder(Printer.Types.TERM);
        int number = 2;

        // ACT
        IPrinter printer = b.level(number).build();

        // ASSERT
        assertThat(printer, not(equalTo(null)));
        assertThat(printer.getLevel(), equalTo(number));
    }

    @Test
    public void Printer_Creation_BuilderChaining() {
        // ARRANGE
        Printer.Builder b = new Printer.Builder(Printer.Types.TERM);
        int number = 3;

        // ACT
        IPrinter printer = b.timestamping(true).level(number).build();
        System.out.print(printer.toString());

        // ASSERT
        assertThat(printer, not(equalTo(null)));
        assertThat(printer.getLevel(), equalTo(number));
    }

    @Test
    public void Printer_Creation_PassingBuilderToConstructor() {
        // ARRANGE
        Printer.Builder b = new Printer.Builder(Printer.Types.TERM);
        int number = 3;

        // ACT
        b.level(3).timestamping(true);
        IPrinter printer = new Printer(b);

        // ASSERT
        assertThat(printer, not(equalTo(null)));
        assertThat(printer.getLevel(), equalTo(number));
    }
}

@@ -183,24 +183,89 @@
 unit.Test;%0A%0A
+import java.text.DateFormat;%0Aimport java.text.SimpleDateFormat;%0A%0A
 import stati
@@ -1716,32 +1716,92 @@
 er.Types.TERM);%0A
+        DateFormat df = new SimpleDateFormat(%22yyyy/MM/dd%22);%0A
         int numb
@@ -1853,16 +1853,41 @@
 ter = b.
+type(Printer.Types.TERM).
 timestam
@@ -1903,32 +1903,47 @@
 ).level(number).
+withFormat(df).
 build();%0A       

Improve Printer_Creation_BuilderChaining to use all possible builders