You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.1 KiB
83 lines
2.1 KiB
package de.edu.hsfulda.ciip.tdd;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.PrintStream;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.extension.ExtendWith;
|
|
import org.mockito.InOrder;
|
|
import org.mockito.Mock;
|
|
import org.mockito.Mockito;
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
|
@ExtendWith(MockitoExtension.class)
|
|
class TannenbaumUiTest {
|
|
|
|
@Mock
|
|
PrintStream output;
|
|
|
|
@Mock
|
|
InputStream input;
|
|
|
|
@Test
|
|
void parseUserInputToInteger() throws IOException {
|
|
Mockito.doReturn(1).when(input).available();
|
|
Mockito.doReturn((int) '7').when(input).read();
|
|
int expected = 7;
|
|
|
|
int treeSize = new TannenbaumUi(input, output).getTreeSize();
|
|
|
|
assertEquals(expected, treeSize, "tree size");
|
|
|
|
InOrder inOrder = Mockito.inOrder(input, output);
|
|
|
|
inOrder.verify(output).println(TannenbaumUi.TREE_SIZE_PROMPT);
|
|
inOrder.verify(input).available();
|
|
}
|
|
|
|
@Test
|
|
void parseUserInputToInteger2() throws IOException {
|
|
Mockito.doReturn(1).when(input).available();
|
|
Mockito.doReturn((int) '9').when(input).read();
|
|
int expected = 9;
|
|
|
|
int treeSize = new TannenbaumUi(input, output).getTreeSize();
|
|
|
|
assertEquals(expected, treeSize, "tree size");
|
|
}
|
|
|
|
@Test
|
|
void parseUserInputToInteger2Digits() throws IOException {
|
|
Mockito.doReturn(2).when(input).available();
|
|
Mockito.doReturn((int) '3').doReturn((int) '5').when(input).read();
|
|
int expected = 35;
|
|
|
|
int treeSize = new TannenbaumUi(input, output).getTreeSize();
|
|
|
|
assertEquals(expected, treeSize, "tree size");
|
|
}
|
|
|
|
@Test
|
|
void writeSingleLine() throws Exception {
|
|
String message = "hello world";
|
|
|
|
new TannenbaumUi(input, output).print(Arrays.asList(message));
|
|
|
|
Mockito.verify(output).println(message);
|
|
}
|
|
|
|
@Test
|
|
void writeMultipeleLines() throws Exception {
|
|
List<String> messageLines = Arrays.asList("hello", "world");
|
|
|
|
new TannenbaumUi(input, output).print(messageLines);
|
|
|
|
Mockito.verify(output).println(messageLines.get(0));
|
|
Mockito.verify(output).println(messageLines.get(1));
|
|
}
|
|
}
|