Path: blob/master/test/jdk/java/lang/System/Logger/Level/LoggerLevelTest.java
41154 views
/*1* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.lang.System.Logger.Level;24import java.util.EnumSet;25import java.util.Objects;26import java.util.Set;27/**28* @test29* @bug 814036430* @summary Tests System.Logger.Level names and severity.31* @author danielfuchs32* @modules java.logging33*/34public class LoggerLevelTest {35public static void main(String[] args) {36Set<Level> untested = EnumSet.allOf(Level.class);37testLevel(untested, Level.ALL, java.util.logging.Level.ALL);38testLevel(untested, Level.TRACE, java.util.logging.Level.FINER);39testLevel(untested, Level.DEBUG, java.util.logging.Level.FINE);40testLevel(untested, Level.INFO, java.util.logging.Level.INFO);41testLevel(untested, Level.WARNING, java.util.logging.Level.WARNING);42testLevel(untested, Level.ERROR, java.util.logging.Level.SEVERE);43testLevel(untested, Level.OFF, java.util.logging.Level.OFF);44if (!untested.isEmpty()) {45throw new RuntimeException("Some level values were not tested: " + untested);46}47}4849private static void testLevel(Set<Level> untested, Level systemLevel, java.util.logging.Level julLevel) {50untested.remove(systemLevel);51assertEquals(systemLevel.getName(), systemLevel.name(),52"System.Logger.Level." + systemLevel.name() + ".getName()");53assertEquals(systemLevel.getSeverity(), julLevel.intValue(),54"System.Logger.Level." + systemLevel.name() + ".getSeverity");55}5657private static void assertEquals(Object actual, Object expected, String what) {58if (!Objects.equals(actual, expected)) {59throw new RuntimeException("Bad value for " + what60+ "\n\t expected: " + expected61+ "\n\t actual: " + actual);62} else {63System.out.println("Got expected value for " + what + ": " + actual);64}65}6667private static void assertEquals(int actual, int expected, String what) {68if (!Objects.equals(actual, expected)) {69throw new RuntimeException("Bad value for " + what70+ "\n\t expected: " + toString(expected)71+ "\n\t actual: " + toString(actual));72} else {73System.out.println("Got expected value for " + what + ": " + toString(actual));74}75}7677private static String toString(int value) {78switch (value) {79case Integer.MAX_VALUE: return "Integer.MAX_VALUE";80case Integer.MIN_VALUE: return "Integer.MIN_VALUE";81default:82return Integer.toString(value);83}84}8586}878889