• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 The Guava Authors
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 package com.google.common.base;
18 
19 import junit.framework.TestCase;
20 
21 /**
22  * Tests for {@link StandardSystemProperty}.
23  *
24  * @author Kurt Alfred Kluever
25  */
26 public class StandardSystemPropertyTest extends TestCase {
27 
testGetKeyMatchesString()28   public void testGetKeyMatchesString() {
29     for (StandardSystemProperty property : StandardSystemProperty.values()) {
30       String fieldName = property.name();
31       String expected = Ascii.toLowerCase(fieldName).replaceAll("_", ".");
32       assertEquals(expected, property.key());
33     }
34   }
35 
testGetValue()36   public void testGetValue() {
37     for (StandardSystemProperty property : StandardSystemProperty.values()) {
38       assertEquals(System.getProperty(property.key()), property.value());
39     }
40   }
41 
testToString()42   public void testToString() {
43     for (StandardSystemProperty property : StandardSystemProperty.values()) {
44       assertEquals(property.key() + "=" + property.value(), property.toString());
45     }
46   }
47 
testNoNullValues()48   public void testNoNullValues() {
49     for (StandardSystemProperty property : StandardSystemProperty.values()) {
50       // Even though the contract in System.getProperties() specifies that a value will exist for
51       // all of the listed keys, for some reason the "java.compiler" key returns null in some JVMs.
52       if (property != StandardSystemProperty.JAVA_COMPILER) {
53         assertNotNull(property.value());
54       }
55     }
56   }
57 }
58