@@ -37,7 +37,34 @@ public void testRemoveObsoleteEntryFromWindowsPath() {
3737 assertThat (IdeasyCommandlet .removeObsoleteEntryFromWindowsPath (path )).isEqualTo (path );
3838 }
3939
40- /** Test of {@link IdeasyCommandlet#installIdeasy(Path)}. */
40+ /**
41+ * Tests if the installation on windows did not add a 2nd path to IDEasy to the PATH environment variable and instead removed the old one and updated it.
42+ * See:
43+ * <a href="https://github.com/devonfw/IDEasy/issues/1559">#1559</a> for reference.
44+ */
45+ @ Test
46+ public void testInstallDoesNotAddPathEntryTwiceOnWindows () {
47+ // arrange
48+ SystemInfo systemInfo = SystemInfoMock .of ("windows" );
49+ IdeTestContext context = newContext ("install" );
50+ context .setIdeRoot (null );
51+ context .setSystemInfo (systemInfo );
52+ context .getStartContext ().setForceMode (true );
53+ WindowsHelper helper = context .getWindowsHelper ();
54+ String originalPath = helper .getUserEnvironmentValue ("PATH" );
55+ IdeasyCommandlet ideasy = new IdeasyCommandlet (context );
56+ // act
57+ ideasy .installIdeasy (context .getUserHome ().resolve ("Downloads/ide-cli" ));
58+ String newPath = originalPath .replace ("C:\\ projects\\ _ide\\ installation\\ bin;" , "" );
59+ // assert
60+ assertThat (helper .getUserEnvironmentValue ("PATH" )).isEqualTo (newPath + ";" + context .getUserHome ().resolve ("projects/_ide/installation/bin" ));
61+ }
62+
63+ /**
64+ * Test of {@link IdeasyCommandlet#installIdeasy(Path)}.
65+ *
66+ * @param os to use
67+ */
4168 @ ParameterizedTest
4269 @ ValueSource (strings = { "windows" , "mac" , "linux" })
4370 public void testInstallIdeasy (String os ) {
@@ -51,7 +78,7 @@ public void testInstallIdeasy(String os) {
5178 WindowsHelper helper = context .getWindowsHelper ();
5279 String originalPath = helper .getUserEnvironmentValue ("PATH" );
5380 if (systemInfo .isWindows ()) {
54- helper .setUserEnvironmentValue ("PATH" , "C:\\ projects\\ _ide\\ bin;" + originalPath );
81+ helper .setUserEnvironmentValue ("PATH" , "C:\\ projects\\ _ide\\ installation \\ bin;" + originalPath );
5582 }
5683 Path ideRoot = context .getUserHome ().resolve ("projects" );
5784 String addedRcLines =
@@ -73,7 +100,8 @@ public void testInstallIdeasy(String os) {
73100 verifyInstallation (releasePath );
74101 if (systemInfo .isWindows ()) {
75102 assertThat (helper .getUserEnvironmentValue ("IDE_ROOT" )).isEqualTo (ideRoot .toString ());
76- assertThat (helper .getUserEnvironmentValue ("PATH" )).isEqualTo (originalPath + ";" + context .getUserHome ().resolve ("projects/_ide/installation/bin" ));
103+ String newPath = originalPath .replace ("C:\\ projects\\ _ide\\ installation\\ bin;" , "" );
104+ assertThat (helper .getUserEnvironmentValue ("PATH" )).isEqualTo (newPath + ";" + context .getUserHome ().resolve ("projects/_ide/installation/bin" ));
77105 assertThat (context .getUserHome ().resolve (".gitconfig" )).hasContent ("[core]\n longpaths = true" );
78106 }
79107 assertThat (context .getUserHome ().resolve (".bashrc" )).hasContent (addedRcLines );
0 commit comments