use of java.util.logging.Logger in project AuthMeReloaded by AuthMe.
the class TestHelper method setupLogger.
/**
* Assign the necessary fields on ConsoleLogger with mocks.
*
* @return The logger mock used
*/
public static Logger setupLogger() {
Logger logger = Mockito.mock(Logger.class);
ConsoleLogger.setLogger(logger);
return logger;
}
use of java.util.logging.Logger in project AuthMeReloaded by AuthMe.
the class OnStartupTasksTest method shouldNotDisplayLegacyHintForWrongCause.
@Test
public void shouldNotDisplayLegacyHintForWrongCause() {
// given
Logger logger = TestHelper.setupLogger();
// when
OnStartupTasks.verifyIfLegacyJarIsNeeded();
// then
verifyZeroInteractions(logger);
}
use of java.util.logging.Logger in project jdk8u_jdk by JetBrains.
the class TestLoggingWithMainAppContext method main.
public static void main(String[] args) throws IOException {
System.out.println("Creating loggers.");
// These loggers will be created in the default user context.
final Logger foo1 = Logger.getLogger("foo");
final Logger bar1 = Logger.getLogger("foo.bar");
if (bar1.getParent() != foo1) {
throw new RuntimeException("Parent logger of bar1 " + bar1 + " is not " + foo1);
}
System.out.println("bar1.getParent() is the same as foo1");
// Set a security manager
System.setSecurityManager(new SecurityManager());
System.out.println("Now running with security manager");
// Triggers the creation of the main AppContext
ByteArrayInputStream is = new ByteArrayInputStream(new byte[] { 0, 1 });
// triggers calls to system loggers & creation of main AppContext
ImageIO.read(is);
// verify that we're still using the default user context
final Logger bar2 = Logger.getLogger("foo.bar");
if (bar1 != bar2) {
throw new RuntimeException("bar2 " + bar2 + " is not the same as bar1 " + bar1);
}
System.out.println("bar2 is the same as bar1");
if (bar2.getParent() != foo1) {
throw new RuntimeException("Parent logger of bar2 " + bar2 + " is not foo1 " + foo1);
}
System.out.println("bar2.getParent() is the same as foo1");
final Logger foo2 = Logger.getLogger("foo");
if (foo1 != foo2) {
throw new RuntimeException("foo2 " + foo2 + " is not the same as foo1 " + foo1);
}
System.out.println("foo2 is the same as foo1");
System.out.println("Test passed.");
}
use of java.util.logging.Logger in project jdk8u_jdk by JetBrains.
the class IndirectlyLoadABundle method getLoggerWithNewCL.
private boolean getLoggerWithNewCL(URL[] urls, String loggerName, String bundleName) throws Throwable {
Logger result = null;
;
// Test getLogger("foo"); getLogger("foo", "rbName");
// First do the getLogger() call with no bundle name
URLClassLoader getLoggerCL = new URLClassLoader(urls, null);
Class<?> loadItUpClazz1 = Class.forName("LoadItUp1", true, getLoggerCL);
ClassLoader actual = loadItUpClazz1.getClassLoader();
if (actual != getLoggerCL) {
throw new Exception("LoadItUp1 was loaded by an unexpected CL: " + actual);
}
Object loadItUp1 = loadItUpClazz1.newInstance();
if (bundleName != null) {
Method getLoggerMethod = loadItUpClazz1.getMethod("getLogger", String.class, String.class);
try {
result = (Logger) getLoggerMethod.invoke(loadItUp1, loggerName, bundleName);
} catch (InvocationTargetException ex) {
throw ex.getTargetException();
}
} else {
Method getLoggerMethod = loadItUpClazz1.getMethod("getLogger", String.class);
try {
result = (Logger) getLoggerMethod.invoke(loadItUp1, loggerName);
} catch (InvocationTargetException ex) {
throw ex.getTargetException();
}
}
return result != null;
}
use of java.util.logging.Logger in project jdk8u_jdk by JetBrains.
the class LoggingExceptionTest method main.
public static void main(String[] args) {
Handler handler = new ConsoleHandler();
Logger logger = Logger.getLogger("javax.management.modelmbean");
logger.addHandler(handler);
logger.setLevel(Level.FINEST);
try {
for (int i = 0; i < tests.length; i++) {
System.out.println(">>> DescriptorSupportLoggingTest: Test Case " + i);
DescriptorSupport ds;
String msg = "Instantiate " + tests[i];
System.out.println(msg);
switch(i) {
case 0:
ds = new DescriptorSupport();
break;
case 1:
ds = new DescriptorSupport(10);
break;
case 2:
ds = new DescriptorSupport(new DescriptorSupport().toXMLString());
break;
case 3:
ds = new DescriptorSupport("name1=value1", "name2=value2");
break;
case 4:
ds = new DescriptorSupport(new String[] { "name" }, new Object[] { "value" });
break;
case 5:
ds = new DescriptorSupport(new DescriptorSupport());
break;
case 6:
RequiredModelMBean mbean = new RequiredModelMBean();
NotificationListener nl = new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
}
};
mbean.addAttributeChangeNotificationListener(nl, null, null);
break;
default:
throw new AssertionError();
}
System.out.println(msg + " OK");
}
} catch (Exception e) {
System.out.println("Got unexpected exception = " + e);
String msg = "Test FAILED!";
System.out.println(msg);
throw new IllegalArgumentException(msg);
}
System.out.println("Test PASSED!");
}
Aggregations