Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit ea257c8

Browse files
committed
Changed getResource() per review comments.
1 parent 5965ea2 commit ea257c8

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/test/java/com/mathworks/ci/MatlabBuilderTest.java

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.net.URISyntaxException;
1313
import java.net.URL;
1414
import java.util.List;
15+
import java.util.Optional;
1516
import java.util.concurrent.ExecutionException;
1617
import org.junit.After;
1718
import org.junit.Assert;
@@ -42,6 +43,7 @@ public class MatlabBuilderTest {
4243
private MatlabBuilder matlabBuilder;
4344
private static URL url;
4445
private static String FileSeperator;
46+
private static String VERSION_INFO_XML_FILE = "VersionInfo.xml";
4547

4648
@Rule
4749
public JenkinsRule jenkins = new JenkinsRule();
@@ -87,20 +89,13 @@ public void testTearDown() {
8789
}
8890

8991
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);
10397
}
98+
10499

105100
/*
106101
* Test Case to verify if Build step contains "Run MATLAB Tests" option.
@@ -424,4 +419,8 @@ private FreeStyleBuild getBuildforRunTestAutomatically() throws InterruptedExcep
424419
FreeStyleBuild build = project.scheduleBuild2(0).get();
425420
return build;
426421
}
422+
423+
private URL getResource(String resource) {
424+
return MatlabBuilderTest.class.getClassLoader().getResource(resource);
425+
}
427426
}

0 commit comments

Comments
 (0)