diff --git a/src/main/java/shoe/example/firstproject/App.java b/src/main/java/shoe/example/firstproject/App.java deleted file mode 100644 index 431a954..0000000 --- a/src/main/java/shoe/example/firstproject/App.java +++ /dev/null @@ -1,7 +0,0 @@ -package shoe.example.firstproject; - -public class App { - public static void main(String[] args) { - System.out.println("Hello World!"); - } -} diff --git a/src/main/java/shoe/example/firstproject/ShuntingYardAlgorithm.java b/src/main/java/shoe/example/firstproject/ShuntingYardAlgorithm.java index 3ec1ef1..0f3dd3b 100644 --- a/src/main/java/shoe/example/firstproject/ShuntingYardAlgorithm.java +++ b/src/main/java/shoe/example/firstproject/ShuntingYardAlgorithm.java @@ -1,7 +1,11 @@ package shoe.example.firstproject; + public class ShuntingYardAlgorithm { public String translate(String infixExpression) { - return infixExpression != null ? infixExpression : ""; + String result = infixExpression != null ? infixExpression : ""; + if(!result.matches("\\d*")) + throw new IllegalArgumentException("Badly formed expression"); + return result; } } diff --git a/src/test/java/shoe/example/firstproject/AppTest.java b/src/test/java/shoe/example/firstproject/AppTest.java deleted file mode 100644 index 3a12d70..0000000 --- a/src/test/java/shoe/example/firstproject/AppTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package shoe.example.firstproject; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class AppTest { - private ByteArrayOutputStream byteArrayOutputStream; - private PrintStream originalSystemOut; - - @Before - public void redirectOutput() { - byteArrayOutputStream = new ByteArrayOutputStream(); - PrintStream printStream = new PrintStream(byteArrayOutputStream); - originalSystemOut = System.out; - System.setOut(printStream); - } - - @After - public void restoreOutput() { - System.setOut(originalSystemOut); - } - - @Test - public void testApp() { - App.main(null); - assertThat(byteArrayOutputStream.toString(), is("Hello World!\n")); - } -} diff --git a/src/test/java/shoe/example/firstproject/ShuntingYardAlgorithmTest.java b/src/test/java/shoe/example/firstproject/ShuntingYardAlgorithmTest.java index 336e323..c237e9f 100644 --- a/src/test/java/shoe/example/firstproject/ShuntingYardAlgorithmTest.java +++ b/src/test/java/shoe/example/firstproject/ShuntingYardAlgorithmTest.java @@ -31,4 +31,9 @@ public void shouldReturnNumberUnchanged() { String result = shuntingYardAlgorithm.translate("45"); assertThat(result, is("45")); } + + @Test(expected=RuntimeException.class) + public void shouldRejectOperatorOnly() { + shuntingYardAlgorithm.translate("+"); + } }