1212import java .net .URISyntaxException ;
1313import java .net .URL ;
1414import java .util .List ;
15+ import java .util .concurrent .ExecutionException ;
1516import org .junit .After ;
1617import org .junit .Assert ;
1718import org .junit .Before ;
@@ -87,9 +88,17 @@ public void testTearDown() {
8788
8889 private String getMatlabroot (String version ) throws URISyntaxException {
8990 ClassLoader classLoader = MatlabBuilderTest .class .getClassLoader ();
90- String matlabRoot = new File (
91- classLoader .getResource ("versioninfo/" + version + "/VersionInfo.xml" ).toURI ())
92- .getAbsolutePath ().replace (FileSeperator + "VersionInfo.xml" , "" );
91+ String matlabRoot ;
92+ if (classLoader .getResource ("versioninfo/" + version + "/VersionInfo.xml" ) != null ) {
93+ matlabRoot = new File (
94+ classLoader .getResource ("versioninfo/" + version + "/VersionInfo.xml" ).toURI ())
95+ .getAbsolutePath ().replace (FileSeperator + "VersionInfo.xml" , "" );
96+ } else {
97+ matlabRoot = new File (
98+ classLoader .getResource ("versioninfo/" + "R2017a" + "/VersionInfo.xml" ).toURI ())
99+ .getAbsolutePath ().replace (FileSeperator + "VersionInfo.xml" , "" )
100+ .replace ("R2017a" , version );
101+ }
93102 return matlabRoot ;
94103 }
95104
@@ -290,13 +299,7 @@ public void verifyCustomCommandInvokedForBatchMode() throws Exception {
290299 @ Test
291300 public void verifyRunTestAutomaticallyIsDefault () throws Exception {
292301 this .matlabBuilder .setLocalMatlab (getMatlabroot ("R2018b" ));
293- RunTestsAutomaticallyOption runOption = new RunTestsAutomaticallyOption ();
294- runOption .setTaCoberturaChkBx (true );
295- runOption .setTaJunitChkBx (true );
296- runOption .setTatapChkBx (true );
297- this .matlabBuilder .setTestRunTypeList (runOption );
298- project .getBuildersList ().add (this .matlabBuilder );
299- FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
302+ FreeStyleBuild build = getBuildforRunTestAutomatically ();
300303 jenkins .assertLogContains ("-batch" , build );
301304 jenkins .assertLogContains ("true,true,true" , build );
302305 }
@@ -329,16 +332,10 @@ public void verifyDefaultValueOfgetBooleanByName() throws Exception {
329332
330333 @ Test
331334 public void verifyMatlabVersionOlderThanR17a () throws Exception {
332- this .matlabBuilder .setLocalMatlab (getMatlabroot ("R2018b" ));
333- RunTestsAutomaticallyOption runOption = new RunTestsAutomaticallyOption ();
334- runOption .setTaCoberturaChkBx (true );
335- runOption .setTaJunitChkBx (true );
336- runOption .setTatapChkBx (true );
337- this .matlabBuilder .setTestRunTypeList (runOption );
338- project .getBuildersList ().add (this .matlabBuilder );
339- FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
340- jenkins .assertLogContains ("-batch" , build );
341- jenkins .assertLogContains ("true,true,true" , build );
335+ this .matlabBuilder .setLocalMatlab (getMatlabroot ("R2016b" ));
336+ FreeStyleBuild build = getBuildforRunTestAutomatically ();
337+ jenkins .assertLogContains ("-r" , build );
338+ jenkins .assertLogContains ("try,exit(" , build );
342339 }
343340
344341 /*
@@ -354,12 +351,12 @@ public void verifyEmptyMatlabRootError() throws Exception {
354351 }
355352
356353 /*
357- * Test To verify UI does not throw any error when valid MATLAB root entered
354+ * Test To verify UI does throw error when in valid MATLAB root entered
358355 *
359356 */
360357
361358 @ Test
362- public void verifyInvalidValidMatlabRoot () throws Exception {
359+ public void verifyInvalidMatlabRootDisplaysError () throws Exception {
363360 project .getBuildersList ().add (this .matlabBuilder );
364361 this .matlabBuilder .setLocalMatlab ("/fake/matlab/path" );
365362 HtmlPage page = jenkins .createWebClient ().goTo ("job/test0/configure" );
@@ -372,7 +369,7 @@ public void verifyInvalidValidMatlabRoot() throws Exception {
372369 */
373370
374371 @ Test
375- public void verifyValidMatlabRoot () throws Exception {
372+ public void verifyValidMatlabRootDoesntDisplayError () throws Exception {
376373 project .getBuildersList ().add (this .matlabBuilder );
377374 this .matlabBuilder .setLocalMatlab (getMatlabroot ("R2018b" ));
378375 HtmlPage page = jenkins .createWebClient ().goTo ("job/test0/configure" );
@@ -412,4 +409,19 @@ public void verifyCoberturaError() throws Exception {
412409 String filteredPageText = pageText .replaceFirst (TestMessage .getValue ("Builder.invalid.matlab.root.error" ), "" );
413410 Assert .assertTrue (filteredPageText .contains (TestMessage .getValue ("Builder.invalid.matlab.root.error" )));
414411 }
412+
413+ /*
414+ * Private helper methods for tests
415+ */
416+
417+ private FreeStyleBuild getBuildforRunTestAutomatically () throws InterruptedException , ExecutionException {
418+ RunTestsAutomaticallyOption runOption = new RunTestsAutomaticallyOption ();
419+ runOption .setTaCoberturaChkBx (true );
420+ runOption .setTaJunitChkBx (true );
421+ runOption .setTatapChkBx (true );
422+ this .matlabBuilder .setTestRunTypeList (runOption );
423+ project .getBuildersList ().add (this .matlabBuilder );
424+ FreeStyleBuild build = project .scheduleBuild2 (0 ).get ();
425+ return build ;
426+ }
415427}
0 commit comments