Commit b7ebf5d6 authored by Johanna S. Karras's avatar Johanna S. Karras
Browse files

Updated GuesserTests.java with added IllegalStateException tests in both...

Updated GuesserTests.java with added IllegalStateException tests in both constructors and corrected test code for makeGuess().
parent da6fe676
Showing with 6 additions and 4 deletions
+6 -4
...@@ -79,6 +79,7 @@ public class GuesserTests { ...@@ -79,6 +79,7 @@ public class GuesserTests {
Constructor c = Reflection.getConstructor(RandomHangmanChooser.class, int.class, int.class); Constructor c = Reflection.getConstructor(RandomHangmanChooser.class, int.class, int.class);
assertThrows(IllegalArgumentException.class, () -> Reflection.newInstance(c, -1, 3)); assertThrows(IllegalArgumentException.class, () -> Reflection.newInstance(c, -1, 3));
assertThrows(IllegalArgumentException.class, () -> Reflection.newInstance(c, 3, -1)); assertThrows(IllegalArgumentException.class, () -> Reflection.newInstance(c, 3, -1));
assertThrows(IllegalStateException.class, () -> Reflection.newInstance(c, Integer.MAX_VALUE, 3));
} }
@Order(3) @Order(3)
...@@ -89,8 +90,8 @@ public class GuesserTests { ...@@ -89,8 +90,8 @@ public class GuesserTests {
Constructor c = Reflection.getConstructor(RandomHangmanChooser.class, int.class, int.class); Constructor c = Reflection.getConstructor(RandomHangmanChooser.class, int.class, int.class);
RandomHangmanChooser chooser = Reflection.newInstance(c, 1, 1); RandomHangmanChooser chooser = Reflection.newInstance(c, 1, 1);
Method m = Reflection.getMethod(RandomHangmanChooser.class, "makeGuess", char.class); Method m = Reflection.getMethod(RandomHangmanChooser.class, "makeGuess", char.class);
IntStream.range(0, 20).forEach(i -> assertThrows(IllegalArgumentException.class, () -> m.invoke(m, chooser, 'a' - (i + 1)))); IntStream.range(0, 20).forEach(i -> assertThrows(IllegalArgumentException.class, () -> m.invoke(chooser, (char) ('a' - (i + 1)))));
IntStream.range(0, 20).forEach(i -> assertThrows(IllegalArgumentException.class, () -> m.invoke(m, chooser, 'z' + (i + 1)))); IntStream.range(0, 20).forEach(i -> assertThrows(IllegalArgumentException.class, () -> m.invoke(chooser, (char) ('z' + (i + 1)))));
} }
...@@ -194,6 +195,7 @@ public class GuesserTests { ...@@ -194,6 +195,7 @@ public class GuesserTests {
Constructor c = Reflection.getConstructor(EvilHangmanChooser.class, int.class, int.class); Constructor c = Reflection.getConstructor(EvilHangmanChooser.class, int.class, int.class);
assertThrows(IllegalArgumentException.class, () -> Reflection.newInstance(c, -1, 3)); assertThrows(IllegalArgumentException.class, () -> Reflection.newInstance(c, -1, 3));
assertThrows(IllegalArgumentException.class, () -> Reflection.newInstance(c, 3, -1)); assertThrows(IllegalArgumentException.class, () -> Reflection.newInstance(c, 3, -1));
assertThrows(IllegalStateException.class, () -> Reflection.newInstance(c, Integer.MAX_VALUE, 3));
} }
@Order(2) @Order(2)
...@@ -204,8 +206,8 @@ public class GuesserTests { ...@@ -204,8 +206,8 @@ public class GuesserTests {
Constructor c = Reflection.getConstructor(EvilHangmanChooser.class, int.class, int.class); Constructor c = Reflection.getConstructor(EvilHangmanChooser.class, int.class, int.class);
EvilHangmanChooser chooser = Reflection.newInstance(c, 1, 1); EvilHangmanChooser chooser = Reflection.newInstance(c, 1, 1);
Method m = Reflection.getMethod(EvilHangmanChooser.class, "makeGuess", char.class); Method m = Reflection.getMethod(EvilHangmanChooser.class, "makeGuess", char.class);
IntStream.range(0, 20).forEach(i -> assertThrows(IllegalArgumentException.class, () -> m.invoke(m, chooser, 'a' - (i + 1)))); IntStream.range(0, 20).forEach(i -> assertThrows(IllegalArgumentException.class, () -> m.invoke(chooser, (char) ('a' - (i + 1)))));
IntStream.range(0, 20).forEach(i -> assertThrows(IllegalArgumentException.class, () -> m.invoke(m, chooser, 'z' + (i + 1)))); IntStream.range(0, 20).forEach(i -> assertThrows(IllegalArgumentException.class, () -> m.invoke(chooser, (char) ('z' + (i + 1)))));
} }
@Order(2) @Order(2)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment