Skip to content

Commit

Permalink
Add unit tests for com.alibaba.jvm.sandbox.api.util.GaStringUtils
Browse files Browse the repository at this point in the history
These tests were written using Diffblue Cover.
  • Loading branch information
EricHetti committed Jul 26, 2019
1 parent 35eae8e commit 5af4aab
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.alibaba.jvm.sandbox.api.util;

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

public class GaStringUtilsTests {

@Test
public void testGetJavaClassName() {
Assert.assertEquals("java.lang.String",
GaStringUtils.getJavaClassName(String.class));
}

@Test
public void testGetJavaClassNameArray() {
Assert.assertNull(GaStringUtils.getJavaClassNameArray(null));
Assert.assertNull(GaStringUtils.getJavaClassNameArray(new Class[]{}));

Class[] classes = new Class[]{String.class, Integer.class};
String[] strings =
new String[]{"java.lang.String", "java.lang.Integer"};

Assert.assertArrayEquals(strings,
GaStringUtils.getJavaClassNameArray(classes));
}

@Test
public void testIsEmpty() {
Assert.assertTrue(GaStringUtils.isEmpty(""));
Assert.assertTrue(GaStringUtils.isEmpty(null));

Assert.assertFalse(GaStringUtils.isEmpty("foo"));
}

@Test
public void testMatching() {
Assert.assertFalse(GaStringUtils.matching(null, "bar"));
Assert.assertFalse(GaStringUtils.matching("foo", null));
Assert.assertFalse(GaStringUtils.matching(null, null));
Assert.assertFalse(GaStringUtils.matching("foo", "bar"));
Assert.assertFalse(GaStringUtils.matching("foobar", "foo"));
Assert.assertFalse(GaStringUtils.matching("foobar", "*a"));
Assert.assertFalse(GaStringUtils.matching("foo", "\\o"));
Assert.assertFalse(GaStringUtils.matching("foo", "\\*"));
Assert.assertFalse(GaStringUtils.matching("foo", "f\\?o"));
Assert.assertFalse(GaStringUtils.matching("fooMatching", "fool\\*ing"));

Assert.assertTrue(GaStringUtils.matching("foo", "*"));
Assert.assertTrue(GaStringUtils.matching("foo", "?oo"));
Assert.assertTrue(GaStringUtils.matching("foo", "**o"));
Assert.assertTrue(GaStringUtils.matching("foo", "f?o"));
Assert.assertTrue(GaStringUtils.matching("fooMatching", "foo*"));
Assert.assertTrue(GaStringUtils.matching("fooMatching", "foo*ing"));
}
}

0 comments on commit 5af4aab

Please sign in to comment.