Skip to content

Commit 7bf29b5

Browse files
committed
Add tests for section partial
1 parent f6905cc commit 7bf29b5

2 files changed

Lines changed: 74 additions & 7 deletions

File tree

src/main/java/com/yocto/yoclib/imap/protocol/ProtocolSectionPartial.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public ProtocolSectionPartial(ProtocolAtom atom){
4242
this(atom,null,null,null);
4343
}
4444

45+
@Override
46+
public boolean equals(Object o) {
47+
if (!(o instanceof ProtocolSectionPartial)) return false;
48+
ProtocolSectionPartial that = (ProtocolSectionPartial) o;
49+
return Objects.equals(this.atom, that.atom) && Objects.equals(this.subordinate, that.subordinate) && Objects.equals(this.partialOffset, that.partialOffset) && Objects.equals(this.partialLength, that.partialLength);
50+
}
51+
4552
public ProtocolAtom getAtom() {
4653
return this.atom;
4754
}
@@ -58,13 +65,6 @@ public Integer getPartialLength() {
5865
return this.partialLength;
5966
}
6067

61-
@Override
62-
public boolean equals(Object o) {
63-
if (!(o instanceof ProtocolSectionPartial)) return false;
64-
ProtocolSectionPartial that = (ProtocolSectionPartial) o;
65-
return Objects.equals(this.atom, that.atom) && Objects.equals(this.subordinate, that.subordinate) && Objects.equals(this.partialOffset, that.partialOffset) && Objects.equals(this.partialLength, that.partialLength);
66-
}
67-
6868
@Override
6969
public String toProtocolString() {
7070
StringBuilder sb = new StringBuilder();
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.yocto.yoclib.imap.tests.protocol;
2+
3+
import com.yocto.yoclib.imap.protocol.ProtocolAtom;
4+
import com.yocto.yoclib.imap.protocol.ProtocolObject;
5+
import com.yocto.yoclib.imap.protocol.ProtocolSectionPartial;
6+
import com.yocto.yoclib.imap.protocol.ProtocolSubordinate;
7+
8+
import org.junit.jupiter.api.Test;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
12+
import static org.junit.jupiter.api.Assertions.assertNull;
13+
14+
public class ProtocolSectionPartialTest{
15+
16+
@Test
17+
public void testEquals(){
18+
ProtocolAtom atom = new ProtocolAtom("a");
19+
20+
assertEquals(new ProtocolSectionPartial(atom),new ProtocolSectionPartial(atom));
21+
22+
assertNotEquals(new ProtocolSectionPartial(atom),null);
23+
assertNotEquals(null,new ProtocolSectionPartial(atom));
24+
25+
assertNotEquals(new ProtocolSectionPartial(atom),atom);
26+
assertNotEquals(atom,new ProtocolSectionPartial(atom));
27+
}
28+
29+
@Test
30+
public void testGetAtom(){
31+
assertEquals(new ProtocolAtom("a"),new ProtocolSectionPartial(new ProtocolAtom("a")).getAtom());
32+
}
33+
34+
@Test
35+
public void testGetSubordinate(){
36+
assertNull(new ProtocolSectionPartial(new ProtocolAtom("a")).getSubordinate());
37+
assertEquals(new ProtocolSubordinate(new ProtocolObject[]{
38+
new ProtocolAtom("ab")
39+
}),new ProtocolSectionPartial(new ProtocolAtom("a"),new ProtocolSubordinate(new ProtocolObject[]{
40+
new ProtocolAtom("ab")
41+
})).getSubordinate());
42+
}
43+
44+
@Test
45+
public void testGetPartialOffset(){
46+
assertNull(new ProtocolSectionPartial(new ProtocolAtom("a"),new ProtocolSubordinate(new ProtocolObject[]{
47+
new ProtocolAtom("ab")
48+
})).getPartialOffset());
49+
assertEquals(123,new ProtocolSectionPartial(new ProtocolAtom("a"),new ProtocolSubordinate(new ProtocolObject[]{
50+
new ProtocolAtom("ab")
51+
}),123).getPartialOffset());
52+
}
53+
54+
@Test
55+
public void testGetPartialLength(){
56+
assertNull(new ProtocolSectionPartial(new ProtocolAtom("a"),123).getPartialLength());
57+
assertEquals(456,new ProtocolSectionPartial(new ProtocolAtom("a"),123,456).getPartialLength());
58+
59+
assertNull(new ProtocolSectionPartial(new ProtocolAtom("a"),new ProtocolSubordinate(new ProtocolObject[]{
60+
new ProtocolAtom("ab")
61+
}),123).getPartialLength());
62+
assertEquals(456,new ProtocolSectionPartial(new ProtocolAtom("a"),new ProtocolSubordinate(new ProtocolObject[]{
63+
new ProtocolAtom("ab")
64+
}),123,456).getPartialLength());
65+
}
66+
67+
}

0 commit comments

Comments
 (0)