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

File DateClassTest.java

 

Code metrics

0
17
3
1
89
51
3
0.18
5.67
3
1

Classes

Class Line # Actions
DateClassTest 46 17 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 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.classes;
21   
22    import java.text.SimpleDateFormat;
23    import java.util.Date;
24    import java.util.Locale;
25   
26    import org.junit.Before;
27    import org.junit.Rule;
28    import org.junit.Test;
29    import org.xwiki.component.internal.multi.DelegateComponentManager;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.localization.LocalizationContext;
32    import org.xwiki.test.mockito.MockitoComponentManagerRule;
33   
34    import com.xpn.xwiki.objects.BaseProperty;
35    import com.xpn.xwiki.objects.DateProperty;
36    import com.xpn.xwiki.web.Utils;
37   
38    import static org.junit.Assert.*;
39    import static org.mockito.Mockito.*;
40   
41    /**
42    * Unit tests for {@link DateClass}.
43    *
44    * @version $Id: b870fc7b75e1931701f70487cd9a89ce02caa24f $
45    */
 
46    public class DateClassTest
47    {
48    @Rule
49    public MockitoComponentManagerRule mocker = new MockitoComponentManagerRule();
50   
51    private LocalizationContext localizationContext;
52   
 
53  2 toggle @Before
54    public void setUp() throws Exception
55    {
56  2 DelegateComponentManager contextCM = new DelegateComponentManager();
57  2 contextCM.setComponentManager(mocker);
58  2 mocker.registerComponent(ComponentManager.class, "context", contextCM);
59   
60  2 Utils.setComponentManager(mocker);
61   
62  2 localizationContext = mocker.registerMockComponent(LocalizationContext.class);
63    }
64   
 
65  1 toggle @Test
66    public void fromString()
67    {
68  1 DateClass dateClass = new DateClass();
69  1 dateClass.setDateFormat("MMMM yyyy");
70  1 when(localizationContext.getCurrentLocale()).thenReturn(new Locale("ro"));
71   
72  1 BaseProperty property = dateClass.fromString("octombrie 2015");
73  1 Date date = (Date) property.getValue();
74  1 assertEquals("10 2015", new SimpleDateFormat("MM yyyy").format(date));
75    }
76   
 
77  1 toggle @Test
78    public void toFormString() throws Exception
79    {
80  1 DateClass dateClass = new DateClass();
81  1 dateClass.setDateFormat("MMMM yyyy");
82  1 when(localizationContext.getCurrentLocale()).thenReturn(new Locale("ro"));
83   
84  1 DateProperty property = new DateProperty();
85  1 property.setValue(new SimpleDateFormat("MM/yyyy").parse("10/2015"));
86   
87  1 assertEquals("octombrie 2015", dateClass.toFormString(property));
88    }
89    }