test/java/util/logging/Listeners.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


  71     /**
  72      * Tests that the given listeners are invoked the expected number of
  73      * times.
  74      */
  75     static void test(Listener[] listeners, int... expected) throws Exception {
  76         // reset counts
  77         for (Listener listener : listeners) {
  78             listener.reset();
  79         }
  80 
  81         // re-reading configuration causes events to be fired
  82         LogManager.getLogManager().readConfiguration();
  83 
  84         // check event listeners invoked as expected
  85         for (int i = 0; i < expected.length; i++) {
  86             assertTrue(listeners[i].fireCount() == expected[i],
  87                 "Unexpected event count");
  88         }
  89     }
  90 

  91     public static void main(String[] args) throws Exception {
  92         LogManager logman = LogManager.getLogManager();
  93 
  94         Listener[] listeners = new Listener[2];
  95         Listener listener1 = listeners[0] = new Listener(LogManager.class);
  96         Listener listener2 = listeners[1] = new Listener(LogManager.class);
  97 
  98         // add listeners
  99         logman.addPropertyChangeListener(listener1);
 100         test(listeners, 1, 0);
 101 
 102         logman.addPropertyChangeListener(listener1);
 103         test(listeners, 2, 0);
 104 
 105         logman.addPropertyChangeListener(listener2);
 106         test(listeners, 2, 1);
 107 
 108         // null handling to check for impact on the existing registrations
 109         try {
 110             logman.addPropertyChangeListener(null);




  71     /**
  72      * Tests that the given listeners are invoked the expected number of
  73      * times.
  74      */
  75     static void test(Listener[] listeners, int... expected) throws Exception {
  76         // reset counts
  77         for (Listener listener : listeners) {
  78             listener.reset();
  79         }
  80 
  81         // re-reading configuration causes events to be fired
  82         LogManager.getLogManager().readConfiguration();
  83 
  84         // check event listeners invoked as expected
  85         for (int i = 0; i < expected.length; i++) {
  86             assertTrue(listeners[i].fireCount() == expected[i],
  87                 "Unexpected event count");
  88         }
  89     }
  90 
  91     @SuppressWarnings("deprecation")
  92     public static void main(String[] args) throws Exception {
  93         LogManager logman = LogManager.getLogManager();
  94 
  95         Listener[] listeners = new Listener[2];
  96         Listener listener1 = listeners[0] = new Listener(LogManager.class);
  97         Listener listener2 = listeners[1] = new Listener(LogManager.class);
  98 
  99         // add listeners
 100         logman.addPropertyChangeListener(listener1);
 101         test(listeners, 1, 0);
 102 
 103         logman.addPropertyChangeListener(listener1);
 104         test(listeners, 2, 0);
 105 
 106         logman.addPropertyChangeListener(listener2);
 107         test(listeners, 2, 1);
 108 
 109         // null handling to check for impact on the existing registrations
 110         try {
 111             logman.addPropertyChangeListener(null);