Skip to content

Instantly share code, notes, and snippets.

@arialdomartini
Created October 9, 2014 07:15
Show Gist options
  • Save arialdomartini/b0af26127c06522c3b16 to your computer and use it in GitHub Desktop.
Save arialdomartini/b0af26127c06522c3b16 to your computer and use it in GitHub Desktop.
How Java splits strings
package net.jobrapido.fo.api.v1.resources;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class SplitTest {
@Test
public void aStringSplittedWithItselfIsNotNull() {
final String[] actual = "</span>".split("</span>");
assertNotNull(actual);
}
@Test
public void aStringSplittedWithItselfReturnsAListWithNoElements() {
final String[] actual = "</span>".split("</span>");
assertEquals(0, actual.length);
}
@Test
public void aCharacterBeforeExtractTheCharacterItself() {
final String[] actual = "xxx</span>".split("</span>");
assertEquals("xxx", actual[0]);
}
@Test
public void aStringAfterExtractNothing() {
final String[] actual = "</span>yyy".split("</span>");
assertEquals("", actual[0]);
}
@Test
public void bothStringsBeforeAndAfterExtractNothing() {
final String[] actual = "xxx</span>yyy".split("</span>");
assertEquals("xxx", actual[0]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment