BAEL-6192: Get the Desktop Path in Java (#13581)

This commit is contained in:
ACHRAF TAITAI 2023-03-04 20:12:23 +01:00 committed by GitHub
parent 20c137bdb1
commit 6159c229ac
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package com.baeldung.path;
import org.junit.jupiter.api.Test;
import java.io.File;
import static org.junit.Assert.assertEquals;
import javax.swing.filechooser.FileSystemView;
public class DesktopPathUnitTest {
// Adapt DESKTOP_PATH variable to your own system path
// private static final String DESKTOP_PATH = "C:\\Users\\HRAF\\Desktop";
@Test
public void whenUsingGetUserHomeProperty_thenShouldEqualDesktopPath() {
String desktopPath = System.getProperty("user.home") + File.separator + "Desktop";
// assertEquals(DESKTOP_PATH, desktopPath);
}
@Test
public void whenUsingFileSystemViewGetHomeDirectory_thenShouldEqualDesktopPath() {
FileSystemView view = FileSystemView.getFileSystemView();
File file = view.getHomeDirectory();
String path = file.getPath();
// assertEquals(DESKTOP_PATH, path);
}
}