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

File SystemTest.java

 

Code metrics

0
19
3
1
92
44
3
0.16
6.33
3
1

Classes

Class Line # Actions
SystemTest 36 19 0% 3 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 org.xwiki.environment;
21   
22    import java.io.File;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26    import org.slf4j.helpers.NOPLogger;
27    import org.xwiki.component.manager.ComponentManager;
28    import org.xwiki.component.util.ReflectionUtils;
29   
30    /**
31    * Unit tests for {@link org.xwiki.environment.System}.
32    *
33    * @version $Id: 1a3366c80f29a7d96f9c5c27ee5e2eddaaf4070b $
34    * @since 3.5M1
35    */
 
36    public class SystemTest
37    {
38    private static final File TMPDIR = new File(java.lang.System.getProperty("java.io.tmpdir"), "xwiki-temp");
39   
 
40  1 toggle @Test
41    public void testInitializeWithNoParameter() throws Exception
42    {
43  1 ComponentManager componentManager = System.initialize();
44  1 Assert.assertNotNull(componentManager);
45   
46  1 Environment environment = componentManager.getInstance(Environment.class);
47   
48    // Capture logs so that they don't leak in the test console
49  1 ReflectionUtils.setFieldValue(environment, "logger", NOPLogger.NOP_LOGGER);
50   
51    // Verify that the temporary directory is `java.io.tmpdir`/xwiki-temp/
52  1 Assert.assertEquals(TMPDIR, environment.getTemporaryDirectory());
53   
54    // Verify that the Permanent directory is java.io.tmpdir
55  1 Assert.assertEquals(new File(java.lang.System.getProperty("java.io.tmpdir")),
56    environment.getPermanentDirectory());
57    }
58   
 
59  1 toggle @Test
60    public void testInitializeWithAllDirectoriesSet() throws Exception
61    {
62  1 File permanentDirectory = new File("/permanent");
63  1 File temporaryDirectory = new File("/temporary");
64  1 File resourceDirectory = new File("/resource");
65   
66  1 ComponentManager componentManager =
67    System.initialize(permanentDirectory, resourceDirectory, temporaryDirectory);
68  1 Assert.assertNotNull(componentManager);
69   
70  1 Environment environment = componentManager.getInstance(Environment.class);
71   
72    // Verify the temporary directory
73  1 Assert.assertEquals(temporaryDirectory, environment.getTemporaryDirectory());
74   
75    // Verify the Permanent directory
76  1 Assert.assertEquals(permanentDirectory, environment.getPermanentDirectory());
77    }
78   
 
79  1 toggle @Test
80    public void testDispose() throws Exception
81    {
82  1 ComponentManager componentManager = System.initialize();
83   
84  1 TestComponent testComponent = componentManager.getInstance(TestRole.class);
85   
86  1 Assert.assertFalse(testComponent.isDisposed());
87   
88  1 System.dispose(componentManager);
89   
90  1 Assert.assertTrue(testComponent.isDisposed());
91    }
92    }