Github user GJL commented on a diff in the pull request:
https://github.com/apache/flink/pull/5220#discussion_r159439656
--- Diff:
flink-clients/src/test/java/org/apache/flink/client/cli/CliFrontendStopTest.java
---
@@ -99,6 +69,44 @@ public void testStop() throws Exception {
}
}
+ @Test(expected = CliArgsException.class)
+ public void testUnrecognizedOption() throws Exception {
+ // test unrecognized option
+ String[] parameters = { "-v", "-l" };
+ CliFrontend testFrontend = new
CliFrontend(CliFrontendTestUtils.getConfigDir());
+ testFrontend.stop(parameters);
+
+ fail("Should have failed.");
+ }
+
+ @Test(expected = CliArgsException.class)
+ public void testMissingJobId() throws Exception {
+ // test missing job id
+ String[] parameters = {};
+ CliFrontend testFrontend = new
CliFrontend(CliFrontendTestUtils.getConfigDir());
+ testFrontend.stop(parameters);
+
+ fail("Should have failed.");
+ }
+
+ @Test
+ public void testUnknownJobId() throws Exception {
+ // test unknown job Id
+ JobID jid = new JobID();
+
+ String[] parameters = { jid.toString() };
+ StopTestCliFrontend testFrontend = new
StopTestCliFrontend(true);
+
+ try {
+ testFrontend.stop(parameters);
+ fail("Should have failed.");
+ } catch (IllegalArgumentException ignored) {
+ // expected
+ }
+
+ Mockito.verify(testFrontend.client,
times(1)).stop(any(JobID.class));
--- End diff --
You are already mocking the behavior of the `client` with:
```
doThrow(new IllegalArgumentException("Test
exception")).when(client).stop(any(JobID.class));
```
Therefore the test should fail in the absence of the exception, i.e., if
`stop` is not called. I think this `verify` is not needed:
```
@Test(expected = IllegalArgumentException.class)
public void testUnknownJobId() throws Exception {
// test unknown job Id
JobID jid = new JobID();
String[] parameters = {jid.toString()};
StopTestCliFrontend testFrontend = new
StopTestCliFrontend(true);
testFrontend.stop(parameters);
fail("Should have failed.");
}
```
---