Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using commons-lang3 to replace commons-lang #4225

Merged
merged 3 commits into from
Feb 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rollback Utils#isOSWindows
ruanwenjun committed Feb 13, 2022
commit e5a2763f249bcfbc4276e01259b1f5a10966f8f9
4 changes: 0 additions & 4 deletions apollo-core/pom.xml
Original file line number Diff line number Diff line change
@@ -42,10 +42,6 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- end of util -->
<!-- log -->
<dependency>
Original file line number Diff line number Diff line change
@@ -16,27 +16,18 @@
*/
package com.ctrip.framework.foundation.internals;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import com.google.common.base.Strings;

public class Utils {

/**
* Judge if the given string contains any char.
*
* @param str
* @return true if the given string is blank
*/
public static boolean isBlank(String str) {
return StringUtils.isBlank(str);
return Strings.nullToEmpty(str).trim().isEmpty();
}

/**
* Judge if the system is windows.
*
* @return true if the current system is windows.
*/
public static boolean isOSWindows() {
return SystemUtils.IS_OS_WINDOWS;
String osName = System.getProperty("os.name");
if (Utils.isBlank(osName)) {
return false;
}
return osName.startsWith("Windows");
}
}
Original file line number Diff line number Diff line change
@@ -25,6 +25,11 @@
public class UtilsTest {
private final String actualOsName = System.getProperty("os.name");

@After
public void tearDown() {
System.setProperty("os.name", actualOsName);
}

@Test
public void isBlankTrueGivenNull() {
assertTrue(Utils.isBlank(null));
@@ -52,11 +57,32 @@ public void isBlankFalseGivenWhitespacePadded() {

@Test
public void isOsWindowsTrueGivenWindows10() {
if (actualOsName.startsWith("Windows")) {
assertTrue(Utils.isOSWindows());
} else {
System.setProperty("os.name", "Windows 10");
assertTrue(Utils.isOSWindows());
}

@Test
public void isOSWindowsFalseGivenMacOsX() {
System.setProperty("os.name", "Mac OS X");
assertFalse(Utils.isOSWindows());
}

@Test
public void isOSWindowsFalseGivenBlank() {
System.setProperty("os.name", "");
assertFalse(Utils.isOSWindows());
}

// Explicitly calling out case sensitivity; revisit if Microsoft changes naming convention
@Test
public void isOSWindowsFalseGivenAllUppercaseWindows() {
System.setProperty("os.name", "WINDOWS 10");
assertFalse(Utils.isOSWindows());
}

@Test
public void isOSWindowsFalseGivenAllLowercaseWindows() {
System.setProperty("os.name", "windows 10");
assertFalse(Utils.isOSWindows());
}
}

}