1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.doc

File XWikiAttachmentArchiveTest.java

 

Code metrics

0
15
6
1
93
51
6
0.4
2.5
6
1

Classes

Class Line # Actions
XWikiAttachmentArchiveTest 35 15 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 5 tests. .

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 com.xpn.xwiki.doc;
21   
22    import static org.junit.Assert.*;
23    import static org.mockito.Mockito.*;
24   
25    import org.junit.Before;
26    import org.junit.Test;
27    import org.suigeneris.jrcs.rcs.Archive;
28    import org.suigeneris.jrcs.rcs.Version;
29   
30    /**
31    * Unit tests for {@link XWikiAttachmentArchive}.
32    *
33    * @version $Id: 89f8f5ab1a5f045b0b6a7a57624b5d27a336a2c5 $
34    */
 
35    public class XWikiAttachmentArchiveTest
36    {
37    /**
38    * The object being tested.
39    */
40    private XWikiAttachmentArchive archive = new XWikiAttachmentArchive();
41   
42    private XWikiAttachment attachment = mock(XWikiAttachment.class);
43   
 
44  5 toggle @Before
45    public void setUp()
46    {
47  5 archive.setAttachment(attachment);
48    }
49   
 
50  1 toggle @Test
51    public void getVersionsWhenThereIsNoHistory()
52    {
53  1 Version version = new Version(3, 4);
54  1 when(attachment.getRCSVersion()).thenReturn(version);
55   
56  1 assertArrayEquals(new Version[] {version}, archive.getVersions());
57    }
58   
 
59  1 toggle @Test
60    public void getVersions() throws Exception
61    {
62  1 Archive rcsArchive = new Archive(new Object[] {"line"}, "file.txt", "5.2");
63  1 rcsArchive.addRevision(new Object[] {"line modified"}, "");
64  1 archive.setRCSArchive(rcsArchive);
65   
66  1 assertArrayEquals(new Version[] {new Version(5, 2), new Version(5, 3)}, archive.getVersions());
67    }
68   
 
69  1 toggle @Test
70    public void getCurrentRevisionWhenThereIsNoHistory() throws Exception
71    {
72  1 String version = "1.3";
73  1 when(attachment.getVersion()).thenReturn(version);
74   
75  1 assertEquals(attachment, archive.getRevision(null, version, null));
76    }
77   
 
78  1 toggle @Test
79    public void getRevisionWhenThereIsNoHistory() throws Exception
80    {
81  1 when(attachment.getVersion()).thenReturn("1.1");
82   
83  1 assertNull(archive.getRevision(null, "2.7", null));
84    }
85   
 
86  1 toggle @Test
87    public void getRevisionWhichDoesNotExist() throws Exception
88    {
89  1 archive.setRCSArchive(new Archive(new Object[] {"text"}, "file.txt", "1.2"));
90   
91  1 assertNull(archive.getRevision(null, "7.2", null));
92    }
93    }