Skip to content

Commit

Permalink
Fix bug where comma delimited list doesn't handle single item lists
Browse files Browse the repository at this point in the history
  • Loading branch information
shayaantx committed Feb 21, 2021
1 parent fd9cef8 commit 1611a66
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/botdarr/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ private static StatusEndPoint getDomain(String constant, String name) {
return null;
}

private static List<String> getCommaDelimitedList(String list) {
if (!Strings.isEmpty(list) && list.contains(",")) {
protected static List<String> getCommaDelimitedList(String list) {
if (!Strings.isEmpty(list)) {
if (list.contains(",")) {
return Arrays.asList(list.split(","));
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.7
5.1.8
30 changes: 29 additions & 1 deletion src/test/java/com/botdarr/ConfigTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.botdarr;

import mockit.Deencapsulation;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -9,6 +10,8 @@

import java.io.File;
import java.io.FileOutputStream;
import java.util.Collections;
import java.util.List;
import java.util.Properties;

public class ConfigTests {
Expand All @@ -17,9 +20,34 @@ public void beforeEachTest() {
Deencapsulation.setField(Config.class, "instance", null);
}

@Test
public void getCommaDelimitedList_emptyItemsReturnEmptyList() {
Assert.assertEquals(Collections.emptyList(), Config.getCommaDelimitedList(""));
}

@Test
public void getCommaDelimitedList_nullItemsReturnEmptyList() {
Assert.assertEquals(Collections.emptyList(), Config.getCommaDelimitedList(null));
}

@Test
public void getCommaDelimitedList_singleItemReturnListWithItem() {
List<String> items = Config.getCommaDelimitedList("item1");
Assert.assertEquals(1, items.size());
Assert.assertEquals("item1", items.get(0));
}

@Test
public void getCommaDelimitedList_multipleItemsSplitByCommaReturnItemsInList() {
List<String> items = Config.getCommaDelimitedList("item1,item2");
Assert.assertEquals(2, items.size());
Assert.assertEquals("item1", items.get(0));
Assert.assertEquals("item2", items.get(1));
}

@Test
public void getConfig_invalidCommandPrefixConfigured() throws Exception {
Properties properties = new Properties();
Properties properties = new Properties();
properties.put("discord-token", "#$F#$#");
properties.put("discord-channels", "channel1");
properties.put("command-prefix", "//");
Expand Down

0 comments on commit 1611a66

Please sign in to comment.