Skip to content

Instantly share code, notes, and snippets.

@unclebob
Created October 3, 2010 18:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unclebob/608806 to your computer and use it in GitHub Desktop.
Save unclebob/608806 to your computer and use it in GitHub Desktop.
@RunWith(Suite.class)
@Suite.SuiteClasses({
WrapperTest.DegenerateTests.class,
WrapperTest.wrapWordsTest.class
})
public class WrapperTest {
public static class DegenerateTests {
@Test
public void emptyString() throws Exception {
assertThat(wrap("", 1), equalTo(""));
}
@Test
public void stringShorterThanCol() throws Exception {
assertThat(wrap("this", 10), equalTo("this"));
}
}
public static class wrapWordsTest {
@Test
public void wrapTwoWordsAfterSpace() throws Exception {
assertThat(wrap("word word", 6), equalTo("word\nword"));
}
@Test
public void wrapThreeWordsAfterFirstSpace() throws Exception {
assertThat(wrap("word word word", 6), equalTo("word\nword\nword"));
}
}
}
public class Wrapper {
public static String wrap(String s, int col) {
if (s.length() <= col)
return s;
else
return s.replaceAll(" ", "\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment