Skip to content

Commit 54703b0

Browse files
committed
Add test for creating protocol strings
1 parent 52ce95c commit 54703b0

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

src/test/java/com/yocto/yoclib/imap/tests/protocol/ProtocolStringTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.yocto.yoclib.imap.tests.protocol;
22

3+
import com.yocto.yoclib.imap.protocol.ProtocolAtom;
4+
import com.yocto.yoclib.imap.protocol.ProtocolLiteral;
5+
import com.yocto.yoclib.imap.protocol.ProtocolQuoted;
36
import com.yocto.yoclib.imap.protocol.ProtocolString;
47

58
import org.junit.jupiter.api.Test;
69

710
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
812

913
public class ProtocolStringTest {
1014

@@ -30,4 +34,19 @@ public String toProtocolString() {
3034
}.toString());
3135
}
3236

37+
@Test
38+
public void testStaticCreate(){
39+
assertInstanceOf(ProtocolLiteral.class,ProtocolString.create("\r"));
40+
assertInstanceOf(ProtocolLiteral.class,ProtocolString.create("\n"));
41+
assertInstanceOf(ProtocolQuoted.class,ProtocolString.create(" "));
42+
assertInstanceOf(ProtocolQuoted.class,ProtocolString.create("\t"));
43+
assertInstanceOf(ProtocolQuoted.class,ProtocolString.create(""));
44+
assertInstanceOf(ProtocolAtom.class,ProtocolString.create("a"));
45+
assertInstanceOf(ProtocolAtom.class,ProtocolString.create("ab"));
46+
assertInstanceOf(ProtocolAtom.class,ProtocolString.create("abc"));
47+
assertInstanceOf(ProtocolQuoted.class,ProtocolString.create("a",true));
48+
assertInstanceOf(ProtocolQuoted.class,ProtocolString.create("ab",true));
49+
assertInstanceOf(ProtocolQuoted.class,ProtocolString.create("abc",true));
50+
}
51+
3352
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.yocto.yoclib.imap.tests.protocol;
2+
3+
import com.yocto.yoclib.imap.protocol.ProtocolAtom;
4+
import com.yocto.yoclib.imap.protocol.ProtocolLiteral;
5+
import com.yocto.yoclib.imap.protocol.ProtocolObject;
6+
import com.yocto.yoclib.imap.protocol.ProtocolQuoted;
7+
import com.yocto.yoclib.imap.protocol.ProtocolSubordinate;
8+
9+
import org.junit.jupiter.api.Test;
10+
11+
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
14+
public class ProtocolSubordinateTest {
15+
16+
@Test
17+
public void testGetValue(){
18+
ProtocolAtom a = new ProtocolAtom("a");
19+
ProtocolQuoted ab = new ProtocolQuoted("ab");
20+
ProtocolLiteral abc = new ProtocolLiteral("abc");
21+
22+
assertArrayEquals(new ProtocolObject[]{a},new ProtocolSubordinate(new ProtocolObject[]{a}).getObjects());
23+
assertArrayEquals(new ProtocolObject[]{a,ab},new ProtocolSubordinate(new ProtocolObject[]{a,ab}).getObjects());
24+
assertArrayEquals(new ProtocolObject[]{a,ab,abc},new ProtocolSubordinate(new ProtocolObject[]{a,ab,abc}).getObjects());
25+
}
26+
27+
@Test
28+
public void testToProtocolString(){
29+
ProtocolAtom a = new ProtocolAtom("a");
30+
ProtocolQuoted ab = new ProtocolQuoted("ab");
31+
ProtocolLiteral abc = new ProtocolLiteral("abc");
32+
33+
assertEquals("[a]",new ProtocolSubordinate(new ProtocolObject[]{a}).toProtocolString());
34+
assertEquals("[a \"ab\"]",new ProtocolSubordinate(new ProtocolObject[]{a,ab}).toProtocolString());
35+
assertEquals("[a \"ab\" {3}\r\nabc]",new ProtocolSubordinate(new ProtocolObject[]{a,ab,abc}).toProtocolString());
36+
}
37+
38+
@Test
39+
public void testToString(){
40+
ProtocolAtom a = new ProtocolAtom("a");
41+
ProtocolQuoted ab = new ProtocolQuoted("ab");
42+
ProtocolLiteral abc = new ProtocolLiteral("abc");
43+
44+
assertEquals("ProtocolSubordinate{objects=[ProtocolAtom{value='a'}]}",new ProtocolSubordinate(new ProtocolObject[]{a}).toString());
45+
assertEquals("ProtocolSubordinate{objects=[ProtocolAtom{value='a'}, ProtocolQuoted{value='ab'}]}",new ProtocolSubordinate(new ProtocolObject[]{a,ab}).toString());
46+
assertEquals("ProtocolSubordinate{objects=[ProtocolAtom{value='a'}, ProtocolQuoted{value='ab'}, ProtocolLiteral{value='abc'}]}",new ProtocolSubordinate(new ProtocolObject[]{a,ab,abc}).toString());
47+
}
48+
49+
}

0 commit comments

Comments
 (0)