1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.objects

File DatePropertyTest.java

 

Code metrics

0
13
4
1
90
48
4
0.31
3.25
4
1

Classes

Class Line # Actions
DatePropertyTest 45 13 0% 4 0
1.0100%
 

Contributing tests

This file is covered by 3 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.objects;
21   
22    import static org.junit.Assert.*;
23   
24    import java.sql.Timestamp;
25    import java.util.Date;
26   
27    import org.junit.Before;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.xwiki.model.internal.reference.LocalStringEntityReferenceSerializer;
31    import org.xwiki.test.ComponentManagerRule;
32    import org.xwiki.test.annotation.ComponentList;
33   
34    import com.xpn.xwiki.web.Utils;
35   
36    /**
37    * Unit tests for {@link DateProperty}.
38    *
39    * @version $Id: bf573452d6d3d2cc568b2a4eb6d5d074dab28ead $
40    * @since 5.0M1
41    */
42    @ComponentList({
43    LocalStringEntityReferenceSerializer.class
44    })
 
45    public class DatePropertyTest
46    {
47    @Rule
48    public ComponentManagerRule componentManager = new ComponentManagerRule();
49   
 
50  3 toggle @Before
51    public void setUp()
52    {
53  3 Utils.setComponentManager(this.componentManager);
54    }
55   
 
56  1 toggle @Test
57    public void setValue()
58    {
59  1 Date date = new Date();
60  1 DateProperty property = new DateProperty();
61  1 property.setValue(date);
62  1 assertSame(date, property.getValue());
63    }
64   
65    /**
66    * Verify that we use {@link Date} for storing the date.
67    *
68    * @see "XWIKI-8648: DateProperty#equals pretty much never works between a document loaded from the database and a document loaded from the XAR for example"
69    */
 
70  1 toggle @Test
71    public void setValueWithExtendedDate()
72    {
73  1 Timestamp timestamp = new Timestamp(new Date().getTime());
74  1 DateProperty property = new DateProperty();
75  1 property.setValue(timestamp);
76  1 assertSame(Date.class, property.getValue().getClass());
77  1 assertEquals(timestamp.getTime(), ((Date) property.getValue()).getTime());
78    }
79   
80    /**
81    * Verify that we can set a date that is null (<a href="http://jira.xwiki.org/browse/XWIKI-8837">XWIKI-8837</a>).
82    */
 
83  1 toggle @Test
84    public void setValueWithNullDate()
85    {
86  1 DateProperty property = new DateProperty();
87  1 property.setValue(null);
88  1 assertNull(property.getValue());
89    }
90    }