Skip to content

Commit

Permalink
Add test coverage for Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
joshknopp committed Jan 5, 2022
1 parent 02f0dca commit 6f4b525
Showing 1 changed file with 89 additions and 0 deletions.
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());
}
}
}

0 comments on commit 6f4b525

Please sign in to comment.