DefaultRunner implements Runner { @Override public CommandOutcome run() { return getCommand().run(cli); } DefaultRunner(Cli cli, CommandManager commandManager, ExecutionPlanBuilder executionPlanBuilder); @Override CommandOutcome run();  }
@Test public void testRun() { when(mockCli.commandName()).thenReturn("c1"); Command mockDefault = mockCommand("d1", CommandOutcome.succeeded()); Command mockHelp = mockCommand("h1", CommandOutcome.succeeded()); Command mockC1 = mockCommand("c1", CommandOutcome.succeeded(), "c1o1", "c1o2"); Command mockC2 = mockCommand("c2", CommandOutcome.succeeded(), "c2o1"); CommandOutcome result = run(Optional.of(mockDefault), Optional.of(mockHelp), mockC1, mockC2); assertTrue(result.isSuccess()); verify(mockC1).run(mockCli); verify(mockC2, times(0)).run(mockCli); verify(mockDefault, times(0)).run(mockCli); verify(mockHelp, times(0)).run(mockCli); }
@Test public void testRun_ReverseOrder() { when(mockCli.commandName()).thenReturn("c2"); Command mockDefault = mockCommand("d1", CommandOutcome.succeeded()); Command mockHelp = mockCommand("h1", CommandOutcome.succeeded()); Command mockC1 = mockCommand("c1", CommandOutcome.succeeded(), "c1o1", "c1o2"); Command mockC2 = mockCommand("c2", CommandOutcome.succeeded(), "c2o1"); CommandOutcome result = run(Optional.of(mockDefault), Optional.of(mockHelp), mockC1, mockC2); assertTrue(result.isSuccess()); verify(mockC2).run(mockCli); verify(mockC1, times(0)).run(mockCli); verify(mockDefault, times(0)).run(mockCli); verify(mockHelp, times(0)).run(mockCli); }
@Test public void testRun_NoMatch() { when(mockCli.commandName()).thenReturn("c3"); Command mockDefault = mockCommand("d1", CommandOutcome.succeeded()); Command mockHelp = mockCommand("h1", CommandOutcome.succeeded()); Command mockC1 = mockCommand("c1", CommandOutcome.succeeded(), "c1o1", "c1o2"); Command mockC2 = mockCommand("c2", CommandOutcome.succeeded(), "c2o1"); assertThrows(IllegalStateException.class, () -> run(Optional.of(mockDefault), Optional.of(mockHelp), mockC1, mockC2)); }
@Test public void testRun_NullName_Default() { when(mockCli.commandName()).thenReturn(null); Command mockDefault = mockCommand("d1", CommandOutcome.succeeded()); Command mockHelp = mockCommand("h1", CommandOutcome.succeeded()); Command mockC1 = mockCommand("c1", CommandOutcome.succeeded(), "c1o1", "c1o2"); Command mockC2 = mockCommand("c2", CommandOutcome.succeeded(), "c2o1"); CommandOutcome result = run(Optional.of(mockDefault), Optional.of(mockHelp), mockC1, mockC2); assertTrue(result.isSuccess()); verify(mockC1, times(0)).run(mockCli); verify(mockC2, times(0)).run(mockCli); verify(mockDefault).run(mockCli); verify(mockHelp, times(0)).run(mockCli); }
@Test public void testRun_NullName_Help() { when(mockCli.commandName()).thenReturn(null); Command mockHelp = mockCommand("h1", CommandOutcome.succeeded()); Command mockC1 = mockCommand("c1", CommandOutcome.succeeded(), "c1o1", "c1o2"); Command mockC2 = mockCommand("c2", CommandOutcome.succeeded(), "c2o1"); CommandOutcome result = run(Optional.empty(), Optional.of(mockHelp), mockC1, mockC2); assertTrue(result.isSuccess()); verify(mockC1, times(0)).run(mockCli); verify(mockC2, times(0)).run(mockCli); verify(mockHelp).run(mockCli); }
@Test public void testRun_NullName_NoFallback() { when(mockCli.commandName()).thenReturn(null); Command mockC1 = mockCommand("c1", CommandOutcome.succeeded(), "c1o1", "c1o2"); Command mockC2 = mockCommand("c2", CommandOutcome.succeeded(), "c2o1"); CommandOutcome result = run(Optional.empty(), Optional.empty(), mockC1, mockC2); assertTrue(result.isSuccess()); verify(mockC1, times(0)).run(mockCli); verify(mockC2, times(0)).run(mockCli); }
@Test public void testRun_Failure() { when(mockCli.commandName()).thenReturn("c1"); Command mockC1 = mockCommand("c1", CommandOutcome.failed(-1, "fff"), "c1o1", "c1o2"); Command mockC2 = mockCommand("c2", CommandOutcome.succeeded(), "c2o1"); CommandOutcome result = run(Optional.empty(), Optional.empty(), mockC1, mockC2); assertFalse(result.isSuccess()); assertEquals(-1, result.getExitCode()); assertEquals("fff", result.getMessage()); }