package fi.helsinki.cs.tmc.cli.io;

import java.util.LinkedList;

// This class is used to test program classes
public class TestIo extends Io {

    private StringBuilder printedText;
    private LinkedList<String> linePrompts;
    private LinkedList<Boolean> confirmationPrompts;
    private LinkedList<String> passwordPrompts;

    public TestIo() {
        printedText = new StringBuilder();
        linePrompts = new LinkedList<>();
        passwordPrompts = new LinkedList<>();
        confirmationPrompts = new LinkedList<>();
    }

    public boolean allPromptsUsed() {
        return linePrompts.isEmpty() && passwordPrompts.isEmpty()
                && confirmationPrompts.isEmpty();
    }

    public void addLinePrompt(String prompt) {
        linePrompts.add(prompt);
    }

    public void addPasswordPrompt(String prompt) {
        passwordPrompts.add(prompt);
    }

    public void addConfirmationPrompt(Boolean confirmation) {
        confirmationPrompts.add(confirmation);
    }

    public void clearPrompts() {
        linePrompts.clear();
        confirmationPrompts.clear();
        passwordPrompts.clear();
    }

    public String out() {
        return printedText.toString();
    }

    @Override
    public void print(String str) {
        printedText.append(str);
    }

    @Override
    public String readLine(String prompt) {
        return linePrompts.pop();
    }

    @Override
    public Boolean readConfirmation(String prompt, Boolean defaultToYes) {
        if (confirmationPrompts.size() >= 1) {
            return confirmationPrompts.pop();
        } else {
            return defaultToYes;
        }
    }

    @Override
    public String readPassword(String prompt) {
        return passwordPrompts.pop();
    }

}

@@ -29,16 +29,212 @@
 li.io;%0A%0A
+import static org.hamcrest.CoreMatchers.is;%0Aimport static org.hamcrest.CoreMatchers.not;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.junit.matchers.JUnitMatchers.containsString;%0A%0A
 import j
@@ -347,16 +347,22 @@
 private 
+final 
 StringBu
@@ -384,32 +384,38 @@
 xt;%0A    private 
+final 
 LinkedList%3CStrin
@@ -434,32 +434,38 @@
 ts;%0A    private 
+final 
 LinkedList%3CBoole
@@ -501,16 +501,22 @@
 private 
+final 
 LinkedLi
@@ -1969,10 +1969,429 @@
 %0A    %7D%0A%0A
+    public void assertContains(String contains) %7B%0A        assertThat(out(), containsString(contains));%0A    %7D%0A%0A    public void assertNotContains(String contains) %7B%0A        assertThat(out(), not(containsString(contains)));%0A    %7D%0A%0A    public void assertEquals(String string) %7B%0A        assertThat(out(), is(string));%0A    %7D%0A%0A    public void assertNotEquals(String string) %7B%0A        assertThat(out(), is(not(string)));%0A    %7D%0A
 %7D%0A

Add four new assert methods to TestIo.