test/java/util/logging/MemoryHandlerTest.java

Print this page
rev 6099 : 8003380: Compiler warnings in logging test code
Summary: Use generics, suppress warnings where appropriate, remove unused imports, etc.
Reviewed-by: lancea, chegar


  31 import java.io.IOException;
  32 import java.util.logging.Handler;
  33 import java.util.logging.Level;
  34 import java.util.logging.LogManager;
  35 import java.util.logging.LogRecord;
  36 import java.util.logging.Logger;
  37 import java.util.logging.MemoryHandler;
  38 
  39 public class MemoryHandlerTest {
  40 
  41     static final String CFG_FILE_PROP = "java.util.logging.config.file";
  42     static final String LM_PROP_FNAME = "MemoryHandlerTest.props";
  43     static Logger logger;
  44 
  45     public static void main(String... args) throws IOException {
  46         // load logging.propertes for the test
  47         String tstSrc = System.getProperty("test.src", ".");
  48         File fname = new File(tstSrc, LM_PROP_FNAME);
  49         String prop = fname.getCanonicalPath();
  50         System.setProperty(CFG_FILE_PROP, prop);
  51         LogManager logMgr = LogManager.getLogManager();
  52         // create a logger
  53         logger = Logger.getLogger(MemoryHandlerTest.class.getName());
  54         // don't have parent handlers get log messages
  55         logger.setUseParentHandlers(false);
  56         //
  57         // Test 1,2: create a CustomMemoryHandler which in the config has
  58         // specified a target of CustomTargetHandler.  (1) Make sure that it
  59         // is created and (2) that the target handler is loaded.
  60         //
  61         CustomMemoryHandler cmh = new CustomMemoryHandler();
  62         try {
  63             logger.addHandler(cmh);
  64         } catch (RuntimeException rte) {
  65             throw new RuntimeException(
  66                 "Test Failed: did not load java.util.logging.ConsoleHandler as expected",
  67                 rte);
  68         }
  69         // if we get here and our config has been processed properly, then we
  70         // should have loaded our target handler
  71         if (CustomTargetHandler.numLoaded !=1) {




  31 import java.io.IOException;
  32 import java.util.logging.Handler;
  33 import java.util.logging.Level;
  34 import java.util.logging.LogManager;
  35 import java.util.logging.LogRecord;
  36 import java.util.logging.Logger;
  37 import java.util.logging.MemoryHandler;
  38 
  39 public class MemoryHandlerTest {
  40 
  41     static final String CFG_FILE_PROP = "java.util.logging.config.file";
  42     static final String LM_PROP_FNAME = "MemoryHandlerTest.props";
  43     static Logger logger;
  44 
  45     public static void main(String... args) throws IOException {
  46         // load logging.propertes for the test
  47         String tstSrc = System.getProperty("test.src", ".");
  48         File fname = new File(tstSrc, LM_PROP_FNAME);
  49         String prop = fname.getCanonicalPath();
  50         System.setProperty(CFG_FILE_PROP, prop);
  51         LogManager.getLogManager();
  52         // create a logger
  53         logger = Logger.getLogger(MemoryHandlerTest.class.getName());
  54         // don't have parent handlers get log messages
  55         logger.setUseParentHandlers(false);
  56         //
  57         // Test 1,2: create a CustomMemoryHandler which in the config has
  58         // specified a target of CustomTargetHandler.  (1) Make sure that it
  59         // is created and (2) that the target handler is loaded.
  60         //
  61         CustomMemoryHandler cmh = new CustomMemoryHandler();
  62         try {
  63             logger.addHandler(cmh);
  64         } catch (RuntimeException rte) {
  65             throw new RuntimeException(
  66                 "Test Failed: did not load java.util.logging.ConsoleHandler as expected",
  67                 rte);
  68         }
  69         // if we get here and our config has been processed properly, then we
  70         // should have loaded our target handler
  71         if (CustomTargetHandler.numLoaded !=1) {