Loading src/test/java/cz/muni/fi/pb162/hw01/impl/app/DisplayAppTest.java 0 → 100644 +54 −0 Original line number Diff line number Diff line package cz.muni.fi.pb162.hw01.impl.app; import com.github.stefanbirkner.systemlambda.SystemLambda; import cz.muni.fi.pb162.hw01.impl.Outputs; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; public class DisplayAppTest { private static DisplayApp app = new DisplayApp(); @Test public void shouldPrintEmptyDisplay() throws Exception { assertApplicationRun(1, "", Outputs.TXT_); } @Test public void shouldContainMultipleSymbols() throws Exception { assertApplicationRun(11, "0123456789E", Outputs.TXT_0123456789E); } @Test public void shouldHandleLongerInput() throws Exception { assertApplicationRun(4, "0123456789E", Outputs.TXT_0123); } @Test public void shouldHandleUnknownSymbol() throws Exception { assertApplicationRun(4, "01k2", Outputs.TXT_01E2); } @Test public void shouldHandleShorterInput() throws Exception { assertApplicationRun(6, "8012", Outputs.TXT_8012_); } private static String run(DisplayAppOptions options) throws Exception { return SystemLambda.tapSystemOut(() -> app.run(options)); } private void assertApplicationRun(int size, String text, String expected) throws Exception { var actual = run(new DisplayAppOptions(size, text)); assertThat(removeSuffixNewLine(actual)).isEqualTo(removeSuffixNewLine(expected)); } private static String removeSuffixNewLine(String string) { if (string.endsWith(System.lineSeparator())) { return string.substring(0, string.length() - 1); } return string; } } Loading
src/test/java/cz/muni/fi/pb162/hw01/impl/app/DisplayAppTest.java 0 → 100644 +54 −0 Original line number Diff line number Diff line package cz.muni.fi.pb162.hw01.impl.app; import com.github.stefanbirkner.systemlambda.SystemLambda; import cz.muni.fi.pb162.hw01.impl.Outputs; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; public class DisplayAppTest { private static DisplayApp app = new DisplayApp(); @Test public void shouldPrintEmptyDisplay() throws Exception { assertApplicationRun(1, "", Outputs.TXT_); } @Test public void shouldContainMultipleSymbols() throws Exception { assertApplicationRun(11, "0123456789E", Outputs.TXT_0123456789E); } @Test public void shouldHandleLongerInput() throws Exception { assertApplicationRun(4, "0123456789E", Outputs.TXT_0123); } @Test public void shouldHandleUnknownSymbol() throws Exception { assertApplicationRun(4, "01k2", Outputs.TXT_01E2); } @Test public void shouldHandleShorterInput() throws Exception { assertApplicationRun(6, "8012", Outputs.TXT_8012_); } private static String run(DisplayAppOptions options) throws Exception { return SystemLambda.tapSystemOut(() -> app.run(options)); } private void assertApplicationRun(int size, String text, String expected) throws Exception { var actual = run(new DisplayAppOptions(size, text)); assertThat(removeSuffixNewLine(actual)).isEqualTo(removeSuffixNewLine(expected)); } private static String removeSuffixNewLine(String string) { if (string.endsWith(System.lineSeparator())) { return string.substring(0, string.length() - 1); } return string; } }