1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 3 |
Complexity Density: 0.18 |
|
46 |
|
public class DateClassTest |
47 |
|
{ |
48 |
|
@Rule |
49 |
|
public MockitoComponentManagerRule mocker = new MockitoComponentManagerRule(); |
50 |
|
|
51 |
|
private LocalizationContext localizationContext; |
52 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
53 |
2 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
65 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
77 |
1 |
@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 |
|
} |