Skip to content

Commit

Permalink
Add unit tests for com.alibaba.csp.sentinel.util (alibaba#651)
Browse files Browse the repository at this point in the history
* Add unit test for com.alibaba.csp.sentinel.util.IdUtil
* Add unit tests for com.alibaba.csp.sentinel.util.StringUtil
  • Loading branch information
paulkennethkent authored and sczyh30 committed Apr 9, 2019
1 parent 29f22e3 commit 4cc2542
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 1999-2019 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.csp.sentinel.util;

import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class IdUtilTest {

@Test
public void truncate() {
assertEquals("(foo),(bar),(baz)", IdUtil.truncate(".(foo).,(bar).,(baz)"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright 1999-2019 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.csp.sentinel.util;

import org.junit.Assert;
import org.junit.Test;

public class StringUtilTest {

@Test
public void testCapitalize() {
Assert.assertNull(StringUtil.capitalize(null));
Assert.assertEquals("Foo", StringUtil.capitalize("foo"));
}

@Test
public void testEqualsIgnoreCase() {
Assert.assertFalse(StringUtil.equalsIgnoreCase("", "BCCC"));
Assert.assertFalse(StringUtil.equalsIgnoreCase(null, ""));
Assert.assertTrue(StringUtil.equalsIgnoreCase("", ""));
Assert.assertTrue(StringUtil.equalsIgnoreCase("BcCc", "BCCC"));
Assert.assertTrue(StringUtil.equalsIgnoreCase(null, null));
}

@Test
public void testEquals() {
Assert.assertFalse(StringUtil.equals(null, ""));
Assert.assertFalse(StringUtil.equals("\"", "\"#\"\"\"\"\"\""));
Assert.assertTrue(StringUtil.equals(null, null));
}

@Test
public void testIsBlank() {
Assert.assertFalse(StringUtil.isBlank("!!!!"));
Assert.assertTrue(StringUtil.isBlank(null));
Assert.assertTrue(StringUtil.isBlank("\n\n"));
Assert.assertTrue(StringUtil.isBlank(""));
}

@Test
public void testIsEmpty() {
Assert.assertFalse(StringUtil.isEmpty("bar"));
Assert.assertTrue(StringUtil.isEmpty(""));
}

@Test
public void testIsNotBlank() {
Assert.assertFalse(StringUtil.isNotBlank(""));
Assert.assertTrue(StringUtil.isNotBlank("\"###"));
}

@Test
public void testIsNotEmpty() {
Assert.assertFalse(StringUtil.isNotEmpty(""));
Assert.assertTrue(StringUtil.isNotEmpty("foo"));
}

@Test
public void testTrim() {
Assert.assertNull(StringUtil.trim(null));
Assert.assertEquals("", StringUtil.trim(""));
Assert.assertEquals("foo", StringUtil.trim("foo "));
}

@Test
public void testTrimToEmpty() {
Assert.assertEquals("", StringUtil.trimToEmpty(""));
Assert.assertEquals("", StringUtil.trimToEmpty(null));
}

}

0 comments on commit 4cc2542

Please sign in to comment.