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 static com.google.common.base.StandardSystemProperty.JAVA_COMPILER; 20 import static com.google.common.base.StandardSystemProperty.JAVA_EXT_DIRS; 21 import static com.google.common.truth.Truth.assertWithMessage; 22 23 import com.google.common.annotations.GwtIncompatible; 24 import junit.framework.TestCase; 25 26 /** 27 * Tests for {@link StandardSystemProperty}. 28 * 29 * @author Kurt Alfred Kluever 30 */ 31 @GwtIncompatible 32 public class StandardSystemPropertyTest extends TestCase { 33 testGetKeyMatchesString()34 public void testGetKeyMatchesString() { 35 for (StandardSystemProperty property : StandardSystemProperty.values()) { 36 String fieldName = property.name(); 37 String expected = Ascii.toLowerCase(fieldName).replaceAll("_", "."); 38 assertEquals(expected, property.key()); 39 } 40 } 41 testGetValue()42 public void testGetValue() { 43 for (StandardSystemProperty property : StandardSystemProperty.values()) { 44 assertEquals(System.getProperty(property.key()), property.value()); 45 } 46 } 47 testToString()48 public void testToString() { 49 for (StandardSystemProperty property : StandardSystemProperty.values()) { 50 assertEquals(property.key() + "=" + property.value(), property.toString()); 51 } 52 } 53 testNoNullValues()54 public void testNoNullValues() { 55 for (StandardSystemProperty property : StandardSystemProperty.values()) { 56 // Even though the contract in System.getProperties() specifies that a value will exist for 57 // all of the listed keys, for some reason the "java.compiler" key returns null in some JVMs. 58 if (property == JAVA_COMPILER) { 59 continue; 60 } 61 // Removed in Java 9: 62 // https://docs.oracle.com/javase/9/migrate/toc.htm#JSMIG-GUID-2C896CA8-927C-4381-A737-B1D81D964B7B 63 if (property == JAVA_EXT_DIRS) { 64 continue; 65 } 66 assertWithMessage(property.toString()).that(property.value()).isNotNull(); 67 } 68 } 69 } 70