|
12 | 12 | import java.net.URISyntaxException; |
13 | 13 | import java.net.URL; |
14 | 14 | import java.util.List; |
| 15 | +import java.util.Optional; |
15 | 16 | import java.util.concurrent.ExecutionException; |
16 | 17 | import org.junit.After; |
17 | 18 | import org.junit.Assert; |
@@ -42,6 +43,7 @@ public class MatlabBuilderTest { |
42 | 43 | private MatlabBuilder matlabBuilder; |
43 | 44 | private static URL url; |
44 | 45 | private static String FileSeperator; |
| 46 | + private static String VERSION_INFO_XML_FILE = "VersionInfo.xml"; |
45 | 47 |
|
46 | 48 | @Rule |
47 | 49 | public JenkinsRule jenkins = new JenkinsRule(); |
@@ -87,20 +89,13 @@ public void testTearDown() { |
87 | 89 | } |
88 | 90 |
|
89 | 91 | private String getMatlabroot(String version) throws URISyntaxException { |
90 | | - ClassLoader classLoader = MatlabBuilderTest.class.getClassLoader(); |
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 | | - } |
102 | | - return matlabRoot; |
| 92 | + String defaultVersionInfo = "versioninfo/R2017a/" + VERSION_INFO_XML_FILE; |
| 93 | + String userVersionInfo = "versioninfo/"+version+"/" + VERSION_INFO_XML_FILE; |
| 94 | + URL matlabRootURL = Optional.ofNullable(getResource(userVersionInfo)).orElseGet(() -> getResource(defaultVersionInfo)); |
| 95 | + File matlabRoot = new File(matlabRootURL.toURI()); |
| 96 | + return matlabRoot.getAbsolutePath().replace(FileSeperator + VERSION_INFO_XML_FILE,"").replace("R2017a",version); |
103 | 97 | } |
| 98 | + |
104 | 99 |
|
105 | 100 | /* |
106 | 101 | * Test Case to verify if Build step contains "Run MATLAB Tests" option. |
@@ -424,4 +419,8 @@ private FreeStyleBuild getBuildforRunTestAutomatically() throws InterruptedExcep |
424 | 419 | FreeStyleBuild build = project.scheduleBuild2(0).get(); |
425 | 420 | return build; |
426 | 421 | } |
| 422 | + |
| 423 | + private URL getResource(String resource) { |
| 424 | + return MatlabBuilderTest.class.getClassLoader().getResource(resource); |
| 425 | + } |
427 | 426 | } |
0 commit comments