mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-28 13:15:28 +01:00
Create tests for StringUtils#getStackTrace and StringUtils#getDifference
- Create tests - Make StringUtils final with private constructor (utility class)
This commit is contained in:
parent
920a982794
commit
a462780059
@ -10,10 +10,14 @@ import java.io.StringWriter;
|
|||||||
/**
|
/**
|
||||||
* Utility class for String operations.
|
* Utility class for String operations.
|
||||||
*/
|
*/
|
||||||
public class StringUtils {
|
public final class StringUtils {
|
||||||
|
|
||||||
public static final String newline = System.getProperty("line.separator");
|
public static final String newline = System.getProperty("line.separator");
|
||||||
|
|
||||||
|
private StringUtils() {
|
||||||
|
// Utility class
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the difference of two strings.
|
* Get the difference of two strings.
|
||||||
*
|
*
|
||||||
|
@ -6,7 +6,9 @@ import java.net.MalformedURLException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.stringContainsInOrder;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -97,4 +99,32 @@ public class StringUtilsTest {
|
|||||||
// then
|
// then
|
||||||
assertThat(result, equalTo("[MalformedURLException]: Unrecognized URL format"));
|
assertThat(result, equalTo("[MalformedURLException]: Unrecognized URL format"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldPrintStackTrace() {
|
||||||
|
// given
|
||||||
|
MalformedURLException ex = new MalformedURLException("Unrecognized URL format");
|
||||||
|
|
||||||
|
// when
|
||||||
|
String result = StringUtils.getStackTrace(ex);
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertThat(result, stringContainsInOrder(getClass().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldGetDifferenceWithNullString() {
|
||||||
|
// given/when/then
|
||||||
|
assertThat(StringUtils.getDifference(null, "test"), equalTo(1.0));
|
||||||
|
assertThat(StringUtils.getDifference("test", null), equalTo(1.0));
|
||||||
|
assertThat(StringUtils.getDifference(null, null), equalTo(1.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldGetDifferenceBetweenTwoString() {
|
||||||
|
// given/when/then
|
||||||
|
assertThat(StringUtils.getDifference("test", "taste"), equalTo(0.4));
|
||||||
|
assertThat(StringUtils.getDifference("test", "bear"), equalTo(0.75));
|
||||||
|
assertThat(StringUtils.getDifference("test", "something"), greaterThan(0.88));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user