forked from devonfw/IDEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocalToolCommandletTest.java
More file actions
105 lines (86 loc) · 3.99 KB
/
LocalToolCommandletTest.java
File metadata and controls
105 lines (86 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package com.devonfw.tools.ide.tool;
import java.nio.file.Path;
import java.util.Set;
import org.junit.jupiter.api.Test;
import com.devonfw.tools.ide.common.Tag;
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.log.IdeLogEntry;
/**
* Test of {@link LocalToolCommandlet}.
*/
public class LocalToolCommandletTest extends AbstractIdeContextTest {
/**
* Dummy commandlet extending {@link LocalToolCommandlet} for testing.
*/
public static class LocalToolDummyCommandlet extends LocalToolCommandlet {
LocalToolDummyCommandlet(IdeContext context) {
super(context, "dummy", Set.of(Tag.TEST));
}
}
/**
* Test {@link LocalToolCommandlet#getValidInstalledSoftwareRepoPath(Path, Path)} with a long installation path, as commonly encountered on macOS systems.
*/
@Test
public void testGetValidInstalledSoftwareRepoPathWithLongPath() {
// arrange
Path installPath = Path.of("/projects/_ide/software/default/java/java/21.0.7_6/Contents/Resources/app/");
Path softwareRepoPath = Path.of("/projects/_ide/software/");
Path expectedResultPath = Path.of("/projects/_ide/software/default/java/java/21.0.7_6/");
IdeTestContext context = newContext(PROJECT_BASIC);
LocalToolDummyCommandlet localToolCommandlet = new LocalToolDummyCommandlet(context);
// act
Path resultPath = localToolCommandlet.getValidInstalledSoftwareRepoPath(installPath, softwareRepoPath);
// assert
assertThat(resultPath).isEqualTo(expectedResultPath);
}
/**
* Test {@link LocalToolCommandlet#getValidInstalledSoftwareRepoPath(Path, Path)} with a valid installation path.
*/
@Test
public void testGetValidInstalledSoftwareRepoPathWithValidPath() {
// arrange
Path installPath = Path.of("/projects/_ide/software/default/java/java/21.0.7_6/");
Path softwareRepoPath = Path.of("/projects/_ide/software/");
IdeTestContext context = newContext(PROJECT_BASIC);
LocalToolDummyCommandlet localToolCommandlet = new LocalToolDummyCommandlet(context);
// act
Path resultPath = localToolCommandlet.getValidInstalledSoftwareRepoPath(installPath, softwareRepoPath);
// assert
assertThat(resultPath).isEqualTo(installPath);
}
/**
* Test {@link LocalToolCommandlet#getValidInstalledSoftwareRepoPath(Path, Path)} with an installation path that is too short.
*/
@Test
public void testGetValidInstalledSoftwareRepoPathWithShortPath() {
// arrange
Path installPath = Path.of("/projects/_ide/software/default/java/java/");
Path softwareRepoPath = Path.of("/projects/_ide/software/");
IdeTestContext context = newContext(PROJECT_BASIC);
LocalToolDummyCommandlet localToolCommandlet = new LocalToolDummyCommandlet(context);
// act
Path resultPath = localToolCommandlet.getValidInstalledSoftwareRepoPath(installPath, softwareRepoPath);
// assert
assertThat(resultPath).isNull();
assertThat(context).log().hasEntries(IdeLogEntry.ofWarning("The installation path is faulty " + installPath + "."));
}
/**
* Test {@link LocalToolCommandlet#getValidInstalledSoftwareRepoPath(Path, Path)} with an installation path that completely differs from the software
* repository path.
*/
@Test
public void testGetValidInstalledSoftwareRepoPathWithWrongPath() {
// arrange
Path installPath = Path.of("/projects/IDEasy/workspaces/main/IDEasy/software/java/");
Path softwareRepoPath = Path.of("/projects/_ide/software/");
IdeTestContext context = newContext(PROJECT_BASIC);
LocalToolDummyCommandlet localToolCommandlet = new LocalToolDummyCommandlet(context);
// act
Path resultPath = localToolCommandlet.getValidInstalledSoftwareRepoPath(installPath, softwareRepoPath);
// assert
assertThat(resultPath).isNull();
assertThat(context).log().hasEntries(IdeLogEntry.ofWarning("The installation path is not located within the software repository " + installPath + "."));
}
}