Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-mlb committed Nov 16, 2024
1 parent 045f7f8 commit 616f656
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/emissary/core/IBaseDataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import emissary.core.channels.SeekableByteChannelFactory;
import emissary.directory.DirectoryEntry;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
Expand Down Expand Up @@ -382,7 +383,7 @@ default String getStringParameter(final String key, final String sep) {
*/
default Collection<String> getParameterAsStrings(final String key) {
final var obj = getParameter(key);
if (obj == null || obj.isEmpty() || ((obj.size() == 1) && (obj.get(0) == null))) {
if (CollectionUtils.isEmpty(obj) || ((obj.size() == 1) && (obj.get(0) == null))) {
return Collections.emptyList();
} else if ((obj.size() == 1) && (obj.get(0) instanceof String)) {
return Collections.singletonList((String) obj.get(0));
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/emissary/core/BaseDataObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1463,4 +1463,39 @@ void testNewInputStream() throws IOException {
assertArrayEquals(bytes2, byteArrayOutputStream.toByteArray());
}
}

@Test
void testGetParameterAsString() {
this.b.putParameter("A", 1L);
this.b.appendParameter("A", "TWO");
this.b.appendParameter("A", "THREE");
assertEquals("1", this.b.getParameterAsString("A"));
assertEquals("1;TWO;THREE", this.b.getParameterAsConcatString("A"));

this.b.putParameter("A", 2L);
assertEquals("2", this.b.getParameterAsString("A"));
assertEquals("2", this.b.getParameterAsConcatString("A"));

this.b.putParameter("A", "THREE");
assertEquals("THREE", this.b.getParameterAsString("A"));
assertEquals("THREE", this.b.getParameterAsConcatString("A"));

this.b.putParameter("A", null);
assertNull(this.b.getParameterAsString("A"));
assertNull(this.b.getParameterAsConcatString("A"));

this.b.putParameter("A", "");
assertNull(this.b.getParameterAsString("A"));
assertNull(this.b.getParameterAsConcatString("A"));

assertNull(this.b.getParameterAsString("DNE"));
assertNull(this.b.getParameterAsConcatString("DNE"));

this.b.putParameter("A", null);
this.b.appendParameter("A", "FOUR");
this.b.appendParameter("A", " ");
assertEquals("null", this.b.getParameterAsString("A"));
assertEquals("null;FOUR; ", this.b.getParameterAsConcatString("A"));
}

}

0 comments on commit 616f656

Please sign in to comment.