-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
apollo-core/src/test/java/com/ctrip/framework/foundation/internals/UtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.ctrip.framework.foundation.internals; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* @author Josh Knopp(https://github.com/joshknopp) | ||
*/ | ||
class UtilsTest { | ||
@Nested | ||
class IsBlank { | ||
@Test | ||
void trueGivenNull() { | ||
assertTrue(Utils.isBlank(null)); | ||
} | ||
|
||
@Test | ||
void trueGivenEmpty() { | ||
assertTrue(Utils.isBlank("")); | ||
} | ||
|
||
@Test | ||
void trueGivenWhitespace() { | ||
assertTrue(Utils.isBlank(" ")); | ||
} | ||
|
||
@Test | ||
void falseGivenLoremIpsum() { | ||
String value = "Lorem Ipsum"; | ||
assertFalse(Utils.isBlank("Lorem Ipsum")); | ||
} | ||
|
||
@Test | ||
void falseGivenWhitepsacePadded() { | ||
assertFalse(Utils.isBlank(" Lorem Ipsum ")); | ||
} | ||
} | ||
|
||
@Nested | ||
class IsOsWindows { | ||
private String actualOsName; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
actualOsName = System.getProperty("os.name"); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
System.setProperty("os.name", actualOsName); | ||
} | ||
|
||
@Test | ||
void trueGivenWindows10() { | ||
System.setProperty("os.name", "Windows 10"); | ||
assertTrue(Utils.isOSWindows()); | ||
} | ||
|
||
@Test | ||
void falseGivenMacOsX() { | ||
System.setProperty("os.name", "Mac OS X"); | ||
assertFalse(Utils.isOSWindows()); | ||
} | ||
|
||
@Test | ||
void falseGivenBlank() { | ||
System.setProperty("os.name", ""); | ||
assertFalse(Utils.isOSWindows()); | ||
} | ||
|
||
// Explicitly calling out case sensitivity; author @nobodyiam should confirm whether this is intentional | ||
@Test | ||
void falseGivenAllUppercaseWindows() { | ||
System.setProperty("os.name", "WINDOWS 10"); | ||
assertFalse(Utils.isOSWindows()); | ||
} | ||
|
||
@Test | ||
void falseGivenAllLowercaseWindows() { | ||
System.setProperty("os.name", "windows 10"); | ||
assertFalse(Utils.isOSWindows()); | ||
} | ||
} | ||
} |