Unverified Commit f1984e25 authored by Mathieu Gicquel's avatar Mathieu Gicquel
Browse files

Add test for association between task and context - fix #9

parent 5c09014b
package fr.alma.gtd.server.main.donnees;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class ContextTest {
private Context context;
@BeforeEach
public void setup() {
this.context = new Context();
}
@Test
public void testTaskAssociation(){
Task t1 = new Task();
Task t2 = new Task();
this.context.getTaskReference().add(t1);
assertTrue(this.context.getTaskReference().contains(t1));
assertEquals(this.context,t1.getContext());
this.context.getTaskReference().remove(t1);
assertFalse(this.context.getTaskReference().contains(t1));
assertFalse(t1.getContextReference().isSet());
this.context.getTaskReference().add(t2);
assertTrue(this.context.getTaskReference().contains(t2));
assertTrue(t2.getContextReference().isSet());
}
}
......@@ -34,4 +34,28 @@ class TaskTest {
assertFalse(this.task.getTagsList().contains(t3));
}
@Test
public void testContextAssociation() {
Context c1 = new Context();
Context c2 = new Context();
this.task.setContext(c1);
assertEquals(c1,this.task.getContext());
assertTrue(c1.getTaskReference().contains(this.task));
this.task.setContext(c2);
assertNotEquals(c1,this.task.getContext());
assertEquals(c2,this.task.getContext());
assertFalse(c1.getTaskReference().contains(this.task));
assertTrue(c2.getTaskReference().contains(this.task));
this.task.getContextReference().unset();
assertFalse(this.task.getContextReference().isSet());
assertFalse(c2.getTaskReference().contains(this.task));
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment