BAEL-6773: Get the OS Username in Java (#14848)
* BAEL-6773: Removed Ignored Tests * BAEL-6773: Initializing a New Module * BAEL-6773: user.name Property Example * BAEL-6773: Removed Unused Dependencies
This commit is contained in:
-25
@@ -1,25 +0,0 @@
|
||||
package com.baeldung.system;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore
|
||||
public class WhenDetectingOSUnitTest {
|
||||
|
||||
private DetectOS os = new DetectOS();
|
||||
|
||||
@Test
|
||||
public void whenUsingSystemProperty_shouldReturnOS() {
|
||||
String expected = "Windows 10";
|
||||
String actual = os.getOperatingSystem();
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUsingSystemUtils_shouldReturnOS() {
|
||||
String expected = "Windows 10";
|
||||
String actual = os.getOperatingSystemSystemUtils();
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
package com.baeldung.system.exit;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.security.Permission;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@Ignore("This test is ignored because it tests deprecated code")
|
||||
public class SystemExitUnitTest {
|
||||
|
||||
private SecurityManager securityManager;
|
||||
private SystemExitExample example;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
example = new SystemExitExample();
|
||||
securityManager = System.getSecurityManager();
|
||||
System.setSecurityManager(new NoExitSecurityManager());
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.setSecurityManager(securityManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExit() throws Exception {
|
||||
try {
|
||||
example.readFile();
|
||||
} catch (ExitException e) {
|
||||
assertEquals("Exit status", 2, e.status);
|
||||
}
|
||||
}
|
||||
|
||||
protected static class ExitException extends SecurityException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public final int status;
|
||||
|
||||
public ExitException(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
private static class NoExitSecurityManager extends SecurityManager {
|
||||
@Override
|
||||
public void checkPermission(Permission perm) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkPermission(Permission perm, Object context) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkExit(int status) {
|
||||
super.checkExit(status);
|
||||
throw new ExitException(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user