4 * Copyright 2010 Codist Monk.
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 package net
.sourceforge
.aprog
.tools
;
27 import static org
.junit
.Assert
.*;
29 import java
.lang
.reflect
.Field
;
30 import java
.util
.HashSet
;
33 import net
.sourceforge
.aprog
.tools
.SystemProperties
.MaybeNull
;
35 import org
.junit
.Test
;
38 * Automated tests using JUnit 4 for {@link SystemProperties}.
40 * @author codistmonk (creation 2010-10-24)
42 public final class SystemPropertiesTest
{
45 public final void testKeys() throws Exception
{
46 final Set
<String
> keys
= new HashSet
<String
>();
48 for (final Field field
: SystemProperties
.class.getFields()) {
49 if (String
.class.equals(field
.getType()) && field
.getAnnotation(MaybeNull
.class) == null) {
50 final String key
= field
.get(null).toString();
51 final String fieldSummary
= field
.getName() + " " + key
;
53 assertTrue("Duplicate property " + fieldSummary
, !keys
.contains(key
));
57 assertNotNull("Null property " + fieldSummary
, System
.getProperty(key
));
63 public final void testGetAvailableProcessorCount() {
64 final int processorCount
= SystemProperties
.getAvailableProcessorCount();
66 assertTrue("Processor count " + processorCount
, 0 <= SystemProperties
.getAvailableProcessorCount());
70 public final void testGetJavaIOTemporaryDirectory() {
71 assertNotNull(SystemProperties
.getJavaIOTemporaryDirectory());
75 public final void testGetFilePathSeparator() {
76 assertNotNull(SystemProperties
.getFilePathSeparator());
80 public final void testGetFileSeparator() {
81 assertNotNull(SystemProperties
.getFileSeparator());
85 public final void testGetLineSeparator() {
86 assertNotNull(SystemProperties
.getLineSeparator());
90 public final void testGetOSName() {
91 assertNotNull(SystemProperties
.getOSName());