Skip to content

Instantly share code, notes, and snippets.

@Riggs333
Created November 14, 2016 21:03
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 Riggs333/187605922e8e62c9f8864e573c853022 to your computer and use it in GitHub Desktop.
Save Riggs333/187605922e8e62c9f8864e573c853022 to your computer and use it in GitHub Desktop.
import org.junit.Test;
import java.text.MessageFormat;
import static org.assertj.core.api.Assertions.assertThat;
public class ChoiceFormatTest {
@Test
public void noApples() {
int count = 0;
assertThat(getMessage(count)).isEqualTo("I got no apples");
}
@Test
public void oneApple() {
int count = 1;
assertThat(getMessage(count)).isEqualTo("I got one apple");
}
@Test
public void twoApple() {
int count = 2;
assertThat(getMessage(count)).isEqualTo("I got 2 apples");
}
@Test
public void threeApple() {
int count = 3;
assertThat(getMessage(count)).isEqualTo("I got 3 apples");
}
@Test
public void lotsOfApples() {
int count = 4;
assertThat(getMessage(count)).isEqualTo("I got lots of apples");
}
private String getMessage(int appleCount) {
return MessageFormat.format("I got {0,choice,0#no apples|1#one apple|1<{0} apples|3<lots of apples}", appleCount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment