### Question:
AlgorithmLevelImpl extends QuestionAnswerLevelImpl implements Algorithm { public String get(String input) { if (input.contains(", ")) { String[] inputs = input.split(", "); int[] ints = new int[inputs.length]; try { for (int index = 0; index < inputs.length; index++) { ints[index] = Integer.parseInt(inputs[index]); } return get(ints); } catch (NumberFormatException e) { return get(inputs); } } try { int number = Integer.parseInt(input); return get(number); } catch (NumberFormatException e) { throw new IllegalStateException("You should override one of 'get' methods"); } } AlgorithmLevelImpl(String... input); @Override List<String> getQuestions(); String get(String input); String get(int input); String get(int... input); String get(String... input); static final int MAX_QUESTION_FOR_ONE_INT_ARGUMENT; }### Answer:
@Test public void testIntFormat() { AlgorithmLevelImpl level = mock(AlgorithmLevelImpl.class); when(level.get(anyString())).thenCallRealMethod(); level.get("1"); verify(level).get(1); }
@Test public void testIntsFormat() { AlgorithmLevelImpl level = mock(AlgorithmLevelImpl.class); when(level.get(anyString())).thenCallRealMethod(); level.get("1, 2, 3"); verify(level).get(1, 2, 3); }
@Test public void testStringsFormat() { AlgorithmLevelImpl level = mock(AlgorithmLevelImpl.class); when(level.get(anyString())).thenCallRealMethod(); level.get("qwe, asd, zxc"); verify(level).get("qwe", "asd", "zxc"); }
@Test public void testStringFormat() { AlgorithmLevelImpl level = mock(AlgorithmLevelImpl.class); when(level.get(anyString())).thenCallRealMethod(); try { level.get("qwe"); fail("expected exception"); } catch (IllegalStateException e) { assertEquals("You should override one of 'get' methods", e.getMessage()); } }