Github user tillrohrmann commented on a diff in the pull request:

    https://github.com/apache/flink/pull/750#discussion_r38186682
  
    --- Diff: 
flink-clients/src/test/java/org/apache/flink/client/CliFrontendPackageProgramTest.java
 ---
    @@ -46,186 +43,120 @@
     
     
     public class CliFrontendPackageProgramTest {
    -   
    +
        @BeforeClass
        public static void init() {
                pipeSystemOutToNull();
        }
     
    -   @Test
    -   public void testNonExistingJarFile() {
    -           try {
    -                   CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    +   @Test(expected = FileNotFoundException.class)
    +   public void testNonExistingJarFile() throws Exception {
    +           CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
     
    -                   ProgramOptions options = mock(ProgramOptions.class);
    -                   
when(options.getJarFilePath()).thenReturn("/some/none/existing/path");
    +           ProgramOptions options = mock(ProgramOptions.class);
    +           
when(options.getJarFilePath()).thenReturn("/some/none/existing/path");
     
    -                   try {
    -                           frontend.buildProgram(options);
    -                           fail("should throw an exception");
    -                   }
    -                   catch (FileNotFoundException e) {
    -                           // that's what we want
    -                   }
    -           }
    -           catch (Exception e) {
    -                   e.printStackTrace();
    -                   fail(e.getMessage());
    -           }
    +           frontend.buildProgram(options);
        }
    -   
    -   @Test
    -   public void testFileNotJarFile() {
    -           try {
    -                   CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
     
    -                   ProgramOptions options = mock(ProgramOptions.class);
    -                   
when(options.getJarFilePath()).thenReturn(getNonJarFilePath());
    +   @Test(expected = ProgramInvocationException.class)
    +   public void testFileNotJarFile() throws Exception {
    +           CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
     
    -                   try {
    -                           frontend.buildProgram(options);
    -                           fail("should throw an exception");
    -                   }
    -                   catch (ProgramInvocationException e) {
    -                           // that's what we want
    -                   }
    -           }
    -           catch (Exception e) {
    -                   e.printStackTrace();
    -                   fail(e.getMessage());
    -           }
    +           ProgramOptions options = mock(ProgramOptions.class);
    +           when(options.getJarFilePath()).thenReturn(getNonJarFilePath());
    +
    +           frontend.buildProgram(options);
        }
    -   
    +
        @Test
    -   public void testVariantWithExplicitJarAndArgumentsOption() {
    -           try {
    -                   String[] arguments = {"-j", getTestJarPath(), "-a", 
"--debug", "true", "arg1", "arg2"};
    -                   String[] reducedArguments = new String[] {"--debug", 
"true", "arg1", "arg2"};
    +   public void testVariantWithExplicitJarAndArgumentsOption() throws 
Exception {
    +           String[] arguments = {"-j", getTestJarPath(), "-a", "--debug", 
"true", "arg1", "arg2"};
    +           String[] reducedArguments = new String[] {"--debug", "true", 
"arg1", "arg2"};
     
    -                   RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    -                   assertEquals(getTestJarPath(), 
options.getJarFilePath());
    -                   assertArrayEquals(reducedArguments, 
options.getProgramArgs());
    +           RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    +           assertEquals(getTestJarPath(), options.getJarFilePath());
    +           assertArrayEquals(reducedArguments, options.getProgramArgs());
     
    -                   CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    -                   PackagedProgram prog = frontend.buildProgram(options);
    +           CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    +           PackagedProgram prog = frontend.buildProgram(options);
     
    -                   Assert.assertArrayEquals(reducedArguments, 
prog.getArguments());
    -                   Assert.assertEquals(TEST_JAR_MAIN_CLASS, 
prog.getMainClassName());
    -           }
    -           catch (Exception e) {
    -                   e.printStackTrace();
    -                   fail(e.getMessage());
    -           }
    +           Assert.assertArrayEquals(reducedArguments, prog.getArguments());
    +           Assert.assertEquals(TEST_JAR_MAIN_CLASS, 
prog.getMainClassName());
        }
    -   
    +
        @Test
    -   public void testVariantWithExplicitJarAndNoArgumentsOption() {
    -           try {
    -                   String[] arguments = {"-j", getTestJarPath(), 
"--debug", "true", "arg1", "arg2"};
    -                   String[] reducedArguments = new String[] {"--debug", 
"true", "arg1", "arg2"};
    +   public void testVariantWithExplicitJarAndNoArgumentsOption() throws 
Exception {
    +           String[] arguments = {"-j", getTestJarPath(), "--debug", 
"true", "arg1", "arg2"};
    +           String[] reducedArguments = new String[] {"--debug", "true", 
"arg1", "arg2"};
     
    -                   RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    -                   assertEquals(getTestJarPath(), 
options.getJarFilePath());
    -                   assertArrayEquals(reducedArguments, 
options.getProgramArgs());
    +           RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    +           assertEquals(getTestJarPath(), options.getJarFilePath());
    +           assertArrayEquals(reducedArguments, options.getProgramArgs());
     
    -                   CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    +           CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
     
    -                   PackagedProgram prog = frontend.buildProgram(options);
    +           PackagedProgram prog = frontend.buildProgram(options);
     
    -                   Assert.assertArrayEquals(reducedArguments, 
prog.getArguments());
    -                   Assert.assertEquals(TEST_JAR_MAIN_CLASS, 
prog.getMainClassName());
    -           }
    -           catch (Exception e) {
    -                   e.printStackTrace();
    -                   fail(e.getMessage());
    -           }
    +           Assert.assertArrayEquals(reducedArguments, prog.getArguments());
    +           Assert.assertEquals(TEST_JAR_MAIN_CLASS, 
prog.getMainClassName());
        }
    -   
    +
        @Test
    -   public void testValidVariantWithNoJarAndNoArgumentsOption() {
    -           try {
    -                   String[] arguments = {getTestJarPath(), "--debug", 
"true", "arg1", "arg2"};
    -                   String[] reducedArguments = {"--debug", "true", "arg1", 
"arg2"};
    +   public void testValidVariantWithNoJarAndNoArgumentsOption() throws 
Exception {
    +           String[] arguments = {getTestJarPath(), "--debug", "true", 
"arg1", "arg2"};
    +           String[] reducedArguments = {"--debug", "true", "arg1", "arg2"};
     
    -                   RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    -                   assertEquals(getTestJarPath(), 
options.getJarFilePath());
    -                   assertArrayEquals(reducedArguments, 
options.getProgramArgs());
    +           RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    +           assertEquals(getTestJarPath(), options.getJarFilePath());
    +           assertArrayEquals(reducedArguments, options.getProgramArgs());
     
    -                   CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    +           CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
     
    -                   PackagedProgram prog = frontend.buildProgram(options);
    +           PackagedProgram prog = frontend.buildProgram(options);
     
    -                   Assert.assertArrayEquals(reducedArguments, 
prog.getArguments());
    -                   Assert.assertEquals(TEST_JAR_MAIN_CLASS, 
prog.getMainClassName());
    -           }
    -           catch (Exception e) {
    -                   e.printStackTrace();
    -                   fail(e.getMessage());
    -           }
    +           Assert.assertArrayEquals(reducedArguments, prog.getArguments());
    +           Assert.assertEquals(TEST_JAR_MAIN_CLASS, 
prog.getMainClassName());
        }
    -   
    +
        @Test
    -   public void testNoJarNoArgumentsAtAll() {
    -           try {
    -                   CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    -                   assertTrue(frontend.run(new String[0]) != 0);
    -           }
    -           catch (Exception e) {
    -                   e.printStackTrace();
    -                   fail(e.getMessage());
    -           }
    +   public void testNoJarNoArgumentsAtAll() throws Exception {
    +           CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    +           assertTrue(frontend.run(new String[0]) != 0);
        }
    -   
    -   @Test
    -   public void testNonExistingFileWithArguments() {
    -           try {
    -                   String[] arguments = {"/some/none/existing/path", 
"--debug", "true", "arg1", "arg2"};
    -                   String[] reducedArguments = {"--debug", "true", "arg1", 
"arg2"};
     
    -                   RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    -                   assertEquals(arguments[0], options.getJarFilePath());
    -                   assertArrayEquals(reducedArguments, 
options.getProgramArgs());
    +   @Test(expected = FileNotFoundException.class)
    +   public void testNonExistingFileWithArguments() throws Exception {
    +           String[] arguments = {"/some/none/existing/path", "--debug", 
"true", "arg1", "arg2"};
    +           String[] reducedArguments = {"--debug", "true", "arg1", "arg2"};
     
    -                   CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    +           RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    +           assertEquals(arguments[0], options.getJarFilePath());
    +           assertArrayEquals(reducedArguments, options.getProgramArgs());
     
    -                   try {
    -                           frontend.buildProgram(options);
    -                           fail("Should fail with an exception");
    -                   }
    -                   catch (FileNotFoundException e) {
    -                           // that's what we want
    -                   }
    -           }
    -           catch (Exception e) {
    -                   e.printStackTrace();
    -                   fail(e.getMessage());
    -           }
    +           CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    +
    +           frontend.buildProgram(options);
        }
    -   
    +
        @Test
    -   public void testNonExistingFileWithoutArguments() {
    -           try {
    -                   String[] arguments = {"/some/none/existing/path"};
    +   public void testNonExistingFileWithoutArguments() throws Exception {
    +           String[] arguments = {"/some/none/existing/path"};
     
    -                   RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    -                   assertEquals(arguments[0], options.getJarFilePath());
    -                   assertArrayEquals(new String[0], 
options.getProgramArgs());
    +           RunOptions options = 
CliFrontendParser.parseRunCommand(arguments);
    +           assertEquals(arguments[0], options.getJarFilePath());
    +           assertArrayEquals(new String[0], options.getProgramArgs());
     
    -                   CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
    +           CliFrontend frontend = new 
CliFrontend(CliFrontendTestUtils.getConfigDir());
     
    -                   try {
    -                           frontend.buildProgram(options);
    -                   }
    -                   catch (FileNotFoundException e) {
    -                           // that's what we want
    -                   }
    +           try {
    +                   frontend.buildProgram(options);
                }
    -           catch (Exception e) {
    -                   e.printStackTrace();
    -                   fail(e.getMessage());
    +           catch (FileNotFoundException e) {
    +                   // that's what we want
    --- End diff --
    
    We could also use the `@Test(expected = ... )` annotation.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to