Skip to content

Commit 305c626

Browse files
committed
Implement BooleanChoice support with withBool(String, Boolean)
1 parent b785bdc commit 305c626

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.tinyoverflow</groupId>
88
<artifactId>tolker</artifactId>
9-
<version>0.1.1-SNAPSHOT</version>
9+
<version>0.1.2-SNAPSHOT</version>
1010

1111
<description>A Paper library to make messaging buttery smooth.</description>
1212

src/main/java/me/tinyoverflow/tolker/MessageBuilder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public MessageBuilder withChoice(String key, Number value) {
7474
return this;
7575
}
7676

77+
public MessageBuilder withBool(String key, boolean value)
78+
{
79+
replacements.add(Formatter.booleanChoice(key, value));
80+
return this;
81+
}
82+
7783
public Component build()
7884
{
7985
TagResolver tagResolver = TagResolver.builder().resolvers(replacements).build();

src/test/java/me/tinyoverflow/tolker/MessageBuilderTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ class MessageBuilderTest
1818
void setUp()
1919
{
2020
MemoryBag bag = new MemoryBag();
21-
bag.addMessage("demo", "First <text> Message");
21+
bag.addMessage("first", "First <text> Message");
2222
bag.addMessage("number", "Price: $<price:'en-US':'#.00'>");
2323
bag.addMessage("date", "Christmas: <date:'dd.MM.yyyy'>");
2424
bag.addMessage("choice", "I met <choice:'0#no developer|1#one developer|1<many developers'>!");
25+
bag.addMessage("boolean-true", "Active: <active:'yes':'no'>");
26+
bag.addMessage("boolean-false", "Active: <active:'yes':'no'>");
2527

2628
tolker = new Tolker(bag);
2729
tolker.registerDefaultSerializers();
@@ -72,4 +74,22 @@ void buildWithChoiceFormatter()
7274
.withChoice("choice", 2)
7375
.build()));
7476
}
77+
78+
@Test
79+
void buildWithBooleanChoiceFormatter()
80+
{
81+
assertEquals("Active: yes", PlainTextComponentSerializer.plainText().serialize(tolker.build("boolean-true")
82+
.withBool("active", true)
83+
.build()));
84+
85+
assertEquals("Active: no", PlainTextComponentSerializer.plainText().serialize(tolker.build("boolean-false")
86+
.withBool("active", false)
87+
.build()));
88+
}
89+
90+
@Test
91+
void buildWithStaticEmbed() {
92+
Component component = tolker.build("static-embed").build();
93+
assertEquals("Embed: Plain Message", PlainTextComponentSerializer.plainText().serialize(component));
94+
}
7595
}

0 commit comments

Comments
 (0)