2 * Copyright 2016 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openo.baseservice.util.impl;
19 import java.io.IOException;
21 import org.junit.AfterClass;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.openo.baseservice.util.inf.SystemEnvVariables;
28 import junit.framework.Assert;
30 import mockit.NonStrictExpectations;
31 import mockit.integration.junit4.JMockit;
32 import net.jcip.annotations.NotThreadSafe;
40 * @version 08-Jun-2016
42 @RunWith(JMockit.class)
44 public class SystemEnvVariablesDefImplTest {
49 * @throws java.lang.Exception
53 public static void setUpBeforeClass() throws Exception {
59 * @throws java.lang.Exception
63 public static void tearDownAfterClass() throws Exception {
69 * @throws java.lang.Exception
73 public void setUp() throws Exception {
77 public void testGetAppRootException() throws Exception {
78 new NonStrictExpectations() {
85 file.getCanonicalPath();
86 result = new IOException();
90 final SystemEnvVariables envVars =new SystemEnvVariablesDefImpl();
91 System.setProperty("catalina.base", ".");
92 final String actual = envVars.getAppRoot();
93 Assert.assertEquals(null, actual);
99 * {@link org.openo.baseservice.util.impl.SystemEnvVariablesDefImpl#getAppRoot()}.
104 public void testGetAppRoot() throws Exception {
105 final SystemEnvVariables envVars = new SystemEnvVariablesDefImpl();
106 final File file = new File(".");
107 final String expected = file.getCanonicalPath();
108 System.setProperty("catalina.base", ".");
109 final String actual = envVars.getAppRoot();
110 Assert.assertEquals(expected, actual);