Skip to content

Commit

Permalink
#571 add Messages tests
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Dec 21, 2018
1 parent 8443ab4 commit 5f3995a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions src/test/java/picocli/CommandLineModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2372,4 +2372,53 @@ public void testArgSpecBuilderCompletionCandidates() {

assertEquals(candidates, positional.completionCandidates());
}

@Test
public void testMessagesCopyNull() {
assertNull(Messages.copy(CommandSpec.create(), null));
}

@Test
public void testMessagesCopyNonNull() {
Messages orig = new Messages(CommandSpec.create(), null);
Messages copy = Messages.copy(CommandSpec.create(), orig);
assertNull(copy.resourceBundle());
}

@Test
public void testMessagesCommandSpec() {
CommandSpec spec = CommandSpec.create();
Messages orig = new Messages(spec, null);
assertSame(spec, orig.commandSpec());
}

@Test
public void testMessagesEmpty() {
assertTrue(Messages.empty((Messages) null));
assertTrue(Messages.empty(new Messages(CommandSpec.create(), null)));
}

@Test
public void testMessagesGetStringNullKey() {
String def = "abc";
assertSame(def, new Messages(CommandSpec.create(), null).getString(null, def));
assertSame(def, new Messages(CommandSpec.create(), null).getString("help", def));

ResourceBundle rb = ResourceBundle.getBundle("picocli.SharedMessages");
assertSame(def, new Messages(CommandSpec.create(), rb).getString(null, def));

assertNotEquals(def, new Messages(CommandSpec.create(), rb).getString("help", def));
}

@Test
public void testMessagesGetStringArrayNullKey() {
String[] def = {"abc"};
assertSame(def, new Messages(CommandSpec.create(), null).getStringArray(null, def));
assertSame(def, new Messages(CommandSpec.create(), null).getStringArray("help", def));

ResourceBundle rb = ResourceBundle.getBundle("picocli.SharedMessages");
assertSame(def, new Messages(CommandSpec.create(), rb).getStringArray(null, def));

assertNotEquals(def, new Messages(CommandSpec.create(), rb).getStringArray("usage.description", def));
}
}

0 comments on commit 5f3995a

Please sign in to comment.