test/java/util/logging/Logger/getGlobal/TestGetGlobal.java

Print this page




  40  * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobal
  41  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobal
  42  * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobal
  43  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobal
  44  * @author danielfuchs
  45  */
  46 public class TestGetGlobal {
  47 
  48     final static String[] messages = {
  49         "1. This message should not appear on the console.",
  50         "2. This message should appear on the console.",
  51         "3. This message should now appear on the console too."
  52     };
  53 
  54     static {
  55         System.setProperty("java.util.logging.config.file",
  56             System.getProperty("test.src", ".") + java.io.File.separator + "logging.properties");
  57     }
  58 
  59     public static void main(String... args) {






  60 
  61         Logger.global.info(messages[0]); // at this point LogManager is not
  62              // initialized yet, so this message should not appear.
  63         Logger.getGlobal().info(messages[1]); // calling getGlobal() will
  64              // initialize the LogManager - and thus this message should appear.
  65         Logger.global.info(messages[2]); // Now that the LogManager is
  66              // initialized, this message should appear too.
  67 
  68         final List<String> expected = Arrays.asList(Arrays.copyOfRange(messages, 1, messages.length));
  69         if (!testgetglobal.HandlerImpl.received.equals(expected)) {
  70             throw new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected);


  71         }
  72     }
  73 }


  40  * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobal
  41  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.BadLogManagerImpl TestGetGlobal
  42  * @run main/othervm/timeout=10 -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobal
  43  * @run main/othervm/timeout=10/policy=policy -Djava.security.manager -Djava.util.logging.manager=testgetglobal.DummyLogManagerImpl TestGetGlobal
  44  * @author danielfuchs
  45  */
  46 public class TestGetGlobal {
  47 
  48     final static String[] messages = {
  49         "1. This message should not appear on the console.",
  50         "2. This message should appear on the console.",
  51         "3. This message should now appear on the console too."
  52     };
  53 
  54     static {
  55         System.setProperty("java.util.logging.config.file",
  56             System.getProperty("test.src", ".") + java.io.File.separator + "logging.properties");
  57     }
  58 
  59     public static void main(String... args) {
  60         final String manager = System.getProperty("java.util.logging.manager", null);
  61 
  62         final String description = "TestGetGlobal"
  63             + (System.getSecurityManager() == null ? " " :
  64                " -Djava.security.manager ")
  65             + (manager == null ? "" : "-Djava.util.logging.manager=" + manager);
  66 
  67         Logger.global.info(messages[0]); // at this point LogManager is not
  68              // initialized yet, so this message should not appear.
  69         Logger.getGlobal().info(messages[1]); // calling getGlobal() will
  70              // initialize the LogManager - and thus this message should appear.
  71         Logger.global.info(messages[2]); // Now that the LogManager is
  72              // initialized, this message should appear too.
  73 
  74         final List<String> expected = Arrays.asList(Arrays.copyOfRange(messages, 1, messages.length));
  75         if (!testgetglobal.HandlerImpl.received.equals(expected)) {
  76             System.err.println("Test case failed: " + description);
  77             throw new Error("Unexpected message list: "+testgetglobal.HandlerImpl.received+" vs "+ expected
  78                             + "\n\t"+description);
  79         }
  80     }
  81 }