Skip to content

Commit 6081000

Browse files
committed
Factor out test value; add comment
Signed-off-by: Scott Kurz <skurz@us.ibm.com>
1 parent 5ff8dec commit 6081000

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

tests/src/main/java/io/openliberty/tools/eclipse/test/ut/CommandBuilderTest.java

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,64 @@
1313

1414
package io.openliberty.tools.eclipse.test.ut;
1515

16+
import static io.openliberty.tools.eclipse.test.it.utils.SWTBotPluginOperations.unsetBuildCmdPathInPreferences;
1617
import static org.junit.jupiter.api.Assertions.assertEquals;
1718

19+
import java.io.File;
1820
import java.nio.file.Path;
1921
import java.nio.file.Paths;
2022

23+
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
2124
import org.junit.jupiter.api.Test;
2225

2326
import io.openliberty.tools.eclipse.CommandBuilder;
2427

2528
public class CommandBuilderTest {
2629

30+
2731

32+
/**
33+
* Tests the CommandBuilder builds a mvn invocation using the mvnw wrapper found in the project, even when the preference
34+
* is unset
35+
*
36+
* @throws Exception
37+
*/
2838
@Test
2939
public void testCmdBuilderMvnWrapper() throws Exception {
40+
// This allows the test to prove the wrapper is in use even when the preference is unset, since an empty string preference would
41+
// resolve to "" + "/bin/mvn" = "/bin/mvn" and would typically be an actual path on Unix/Mac
42+
unsetBuildCmdPathInPreferences(new SWTWorkbenchBot(), "Maven");
3043
Path projectPath = Paths.get("resources", "applications", "maven", "liberty-maven-test-wrapper-app");
31-
String pathEnv="C:\\abc;;C:\\xyz";
32-
String retVal = CommandBuilder.getMavenCommandLine(projectPath.toString(), "-a 123", pathEnv, false);
44+
String retVal = CommandBuilder.getMavenCommandLine(projectPath.toString(), "-a 123", obfuscatedPath(), false);
3345
assertEquals(projectPath.resolve(mvnwName()) + " -a 123", retVal, "Wrong cmd line");
3446
}
3547

48+
/**
49+
* Tests the CommandBuilder builds a mvn invocation using the mvn found in the path, even when there is an empty path element
50+
*
51+
* @throws Exception
52+
*/
3653
@Test
3754
public void testCmdBuilderMvn() throws Exception {
3855
Path projectPath = Paths.get("resources", "applications", "maven", "liberty-maven-test-app");
3956
Path mvnPath = Paths.get("resources", "execs");
40-
String mvnPathStr = mvnPath.toAbsolutePath().toString();
41-
42-
String pathEnv= null;
57+
String pathEnv= obfuscatedPath() + File.pathSeparator + mvnPath.toAbsolutePath().toString();
58+
String retVal = CommandBuilder.getMavenCommandLine(projectPath.toString(), "-a 123", pathEnv, false);
59+
assertEquals(mvnPath.toAbsolutePath().resolve(mvnName()) + " -a 123", retVal, "Wrong cmd line");
60+
}
61+
62+
/**
63+
* @return A platform-dependent path very unlikely to be used, with an empty element
64+
*/
65+
private String obfuscatedPath() {
4366
if (System.getProperty("os.name").contains("Windows")) {
44-
pathEnv="C:\\abc;;C:\\xyz;" +mvnPathStr;
67+
return "C:\\abc\\xyz\\123\456;;C:\\xyz\\abc\\456\\123";
4568
} else {
46-
pathEnv="/a/b/c1::/x/y/z1:" +mvnPathStr;
69+
return "/a/b/c/d1/e/f/g::/x/ya/b2/saa/";
4770
}
48-
String retVal = CommandBuilder.getMavenCommandLine(projectPath.toString(), "-a 123", pathEnv, false);
49-
assertEquals(mvnPath.toAbsolutePath().resolve(mvnName()) + " -a 123", retVal, "Wrong cmd line");
5071
}
5172

73+
5274
private String mvnName() {
5375
if (System.getProperty("os.name").contains("Windows")) {
5476
return "mvn.cmd";

0 commit comments

Comments
 (0)