Created
October 3, 2010 18:47
-
-
Save unclebob/608806 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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")); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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