Created
November 29, 2018 15:49
-
-
Save reyabreu/5c1abd222237fb89a41e300590a3e9e4 to your computer and use it in GitHub Desktop.
Unit tests for the format String indexer
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
import org.junit.Test; | |
import static org.hamcrest.Matchers.is; | |
import static org.junit.Assert.assertThat; | |
public class TestFormatStringIndexer { | |
@Test | |
public void index_simpleSpecifiers_ok() { | |
final String result = FormatStringIndexer.index("there are %d apples in the %s basket that cost %f", 1); | |
assertThat(result, is("there are %1$d apples in the %2$s basket that cost %3$f")); | |
} | |
@Test | |
public void index_extendedSpecifiers_ok() { | |
final String result = FormatStringIndexer.index("there are %3d apples in the %s basket that cost %5.2f", 1); | |
assertThat(result, is("there are %1$3d apples in the %2$s basket that cost %3$5.2f")); | |
} | |
@Test | |
public void index_indexedSpecifiers_ok() { | |
final String result = FormatStringIndexer.index("there are %3d apples in the %1$s basket that cost %5.2f", 2); | |
assertThat(result, is("there are %2$3d apples in the %1$s basket that cost %3$5.2f")); | |
} | |
@Test | |
public void index_mixedSpecifiers_ok() { | |
final String result = FormatStringIndexer.index("at %T there are %-2d apples in the %1$s basket and %<$s box that cost %,5.2f", 2); | |
assertThat(result, is("at %2$T there are %3$-2d apples in the %1$s basket and %<$s box that cost %4$,5.2f")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment