Skip to content

Commit f73e80e

Browse files
committed
Add protocol list
1 parent 665729f commit f73e80e

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.yocto.yoclib.imap.protocol;
2+
3+
import java.util.Arrays;
4+
import java.util.stream.Collectors;
5+
6+
public class ProtocolList extends ProtocolObject {
7+
8+
private final ProtocolObject[] value;
9+
10+
public ProtocolList(ProtocolObject[] value){
11+
this.value = value;
12+
}
13+
14+
public ProtocolObject[] getValue() {
15+
return this.value;
16+
}
17+
18+
@Override
19+
public String toProtocolString(){
20+
return "("+Arrays.stream(this.value).map(ProtocolObject::toProtocolString).collect(Collectors.joining(" "))+")";
21+
}
22+
23+
@Override
24+
public String toString() {
25+
return "ProtocolList{" +
26+
"value=" + Arrays.toString(value) +
27+
'}';
28+
}
29+
30+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.yocto.yoclib.imap.tests.protocol;
2+
3+
import com.yocto.yoclib.imap.protocol.*;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
public class ProtocolListTest {
11+
12+
@Test
13+
public void testGetValue(){
14+
ProtocolAtom a = new ProtocolAtom("a");
15+
ProtocolQuoted ab = new ProtocolQuoted("ab");
16+
ProtocolLiteral abc = new ProtocolLiteral("abc");
17+
18+
assertArrayEquals(new ProtocolObject[]{a},new ProtocolList(new ProtocolObject[]{a}).getValue());
19+
assertArrayEquals(new ProtocolObject[]{a,ab},new ProtocolList(new ProtocolObject[]{a,ab}).getValue());
20+
assertArrayEquals(new ProtocolObject[]{a,ab,abc},new ProtocolList(new ProtocolObject[]{a,ab,abc}).getValue());
21+
}
22+
23+
@Test
24+
public void testToProtocolString(){
25+
ProtocolAtom a = new ProtocolAtom("a");
26+
ProtocolQuoted ab = new ProtocolQuoted("ab");
27+
ProtocolLiteral abc = new ProtocolLiteral("abc");
28+
29+
assertEquals("(a)",new ProtocolList(new ProtocolObject[]{a}).toProtocolString());
30+
assertEquals("(a \"ab\")",new ProtocolList(new ProtocolObject[]{a,ab}).toProtocolString());
31+
assertEquals("(a \"ab\" {3}\r\nabc)",new ProtocolList(new ProtocolObject[]{a,ab,abc}).toProtocolString());
32+
}
33+
34+
}

0 commit comments

Comments
 (0)