1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.context

File ExecutionContextTest.java

 

Code metrics

0
32
6
1
112
68
6
0.19
5.33
6
1

Classes

Class Line # Actions
ExecutionContextTest 37 32 0% 6 0
1.0100%
 

Contributing tests

This file is covered by 6 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 org.xwiki.context;
21   
22    import static org.hamcrest.Matchers.hasEntry;
23    import static org.junit.Assert.assertEquals;
24    import static org.junit.Assert.assertNull;
25    import static org.junit.Assert.assertThat;
26    import static org.junit.Assert.assertTrue;
27   
28    import java.util.HashMap;
29    import java.util.Map;
30   
31    import org.junit.Test;
32   
33    /**
34    * @version $Id: fda8f9f9f3dac52e3d96c9bfb2df057e81e3f8ea $
35    * @since 4.3M1
36    */
 
37    public class ExecutionContextTest
38    {
 
39  1 toggle @Test
40    public void inheritance()
41    {
42  1 ExecutionContext context = new ExecutionContext();
43  1 ExecutionContext parent = new ExecutionContext();
44   
45  1 parent.newProperty("inherited").inherited().initial("test").declare();
46   
47  1 parent.newProperty("shadowed").inherited().initial("original").declare();
48   
49  1 context.newProperty("shadowed").inherited().initial("shadowed").declare();
50   
51  1 context.inheritFrom(parent);
52   
53  1 assertTrue(context.getProperty("inherited").equals("test"));
54  1 assertTrue(context.getProperty("shadowed").equals("shadowed"));
55    }
56   
 
57  1 toggle @Test(expected = IllegalStateException.class)
58    public void illegalInheritance()
59    {
60  1 ExecutionContext context = new ExecutionContext();
61  1 ExecutionContext parent = new ExecutionContext();
62   
63  1 parent.newProperty("inherited").inherited().initial("test").makeFinal().declare();
64  1 context.newProperty("inherited").inherited().initial("test").makeFinal().declare();
65   
66  1 context.inheritFrom(parent);
67    }
68   
 
69  1 toggle @Test
70    public void getProperties()
71    {
72  1 ExecutionContext context = new ExecutionContext();
73  1 context.setProperty("key", "value");
74  1 Map<String, Object> properties = context.getProperties();
75  1 assertEquals(1, properties.size());
76  1 assertThat(properties, hasEntry("key", (Object) "value"));
77    }
78   
 
79  1 toggle @Test
80    public void setProperties()
81    {
82  1 Map<String, Object> properties = new HashMap<String, Object>();
83  1 properties.put("key1", "value1");
84  1 properties.put("key2", "value2");
85   
86  1 ExecutionContext context = new ExecutionContext();
87  1 context.setProperties(properties);
88   
89  1 assertEquals("value1", context.getProperty("key1"));
90  1 assertEquals("value2", context.getProperty("key2"));
91    }
92   
 
93  1 toggle @Test
94    public void removeProperty()
95    {
96  1 ExecutionContext context = new ExecutionContext();
97  1 context.setProperty("key", "value");
98   
99  1 assertEquals("value", context.getProperty("key"));
100   
101  1 context.removeProperty("key");
102   
103  1 assertNull(context.getProperty("key"));
104    }
105   
 
106  1 toggle @Test
107    public void removeUnexistingProperty()
108    {
109  1 ExecutionContext context = new ExecutionContext();
110  1 context.removeProperty("doesnotexist");
111    }
112    }