1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.xar.internal.question

File ConflictQuestionRecorderTest.java

 

Code metrics

0
30
1
1
79
45
1
0.03
30
1
1

Classes

Class Line # Actions
ConflictQuestionRecorderTest 38 30 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.xar.internal.question;
21   
22    import org.junit.Test;
23    import org.xwiki.extension.xar.question.ConflictQuestion;
24    import org.xwiki.extension.xar.question.ConflictQuestion.GlobalAction;
25    import org.xwiki.model.reference.DocumentReference;
26   
27    import com.xpn.xwiki.doc.XWikiDocument;
28   
29    import static org.junit.Assert.*;
30    import static org.mockito.Mockito.*;
31   
32    /**
33    * Unit tests for {@link ConflictQuestionRecorder}.
34    *
35    * @version $Id: 6cdf46157cd8ab68d661188d6474b1b80300b3d0 $
36    * @since 7.1RC1
37    */
 
38    public class ConflictQuestionRecorderTest
39    {
 
40  1 toggle @Test
41    public void recordAndReplay()
42    {
43  1 XWikiDocument alice = mock(XWikiDocument.class, "Alice");
44  1 when(alice.getDocumentReference()).thenReturn(new DocumentReference("dev", "Users", "Alice"));
45  1 ConflictQuestion aliceQuestion = new ConflictQuestion(null, null, alice, null);
46  1 aliceQuestion.setGlobalAction(GlobalAction.CURRENT);
47   
48  1 XWikiDocument bob = mock(XWikiDocument.class, "Bob");
49  1 when(bob.getDocumentReference()).thenReturn(new DocumentReference("dev", "Users", "Bob"));
50  1 ConflictQuestion bobQuestion = new ConflictQuestion(null, null, bob, null);
51  1 bobQuestion.setGlobalAction(GlobalAction.PREVIOUS);
52  1 bobQuestion.setAlways(true);
53   
54  1 ConflictQuestionRecorder recorder = new ConflictQuestionRecorder();
55  1 recorder.record(aliceQuestion);
56  1 recorder.record(bobQuestion);
57   
58  1 XWikiDocument carol = mock(XWikiDocument.class, "Carol");
59  1 when(carol.getDocumentReference()).thenReturn(new DocumentReference("drafts", "Users", "Carol"));
60  1 ConflictQuestion carolQuestion = new ConflictQuestion(null, null, carol, null);
61  1 assertFalse(recorder.replay(carolQuestion));
62  1 assertEquals(GlobalAction.MERGED, carolQuestion.getGlobalAction());
63  1 assertFalse(carolQuestion.isAlways());
64   
65  1 XWikiDocument aliceDrafts = mock(XWikiDocument.class, "AliceDrafts");
66  1 when(aliceDrafts.getDocumentReference()).thenReturn(new DocumentReference("drafts", "Users", "Alice"));
67  1 ConflictQuestion aliceDraftsQuestion = new ConflictQuestion(null, null, aliceDrafts, null);
68  1 assertTrue(recorder.replay(aliceDraftsQuestion));
69  1 assertEquals(GlobalAction.CURRENT, aliceDraftsQuestion.getGlobalAction());
70  1 assertFalse(aliceDraftsQuestion.isAlways());
71   
72  1 XWikiDocument bobDrafts = mock(XWikiDocument.class, "BobDrafts");
73  1 when(bobDrafts.getDocumentReference()).thenReturn(new DocumentReference("drafts", "Users", "Bob"));
74  1 ConflictQuestion bobDraftsQuestion = new ConflictQuestion(null, null, bobDrafts, null);
75  1 assertTrue(recorder.replay(bobDraftsQuestion));
76  1 assertEquals(GlobalAction.PREVIOUS, bobDraftsQuestion.getGlobalAction());
77  1 assertTrue(bobDraftsQuestion.isAlways());
78    }
79    }