/** * Class.getEnclosingClass() only exists on JDK5, so reimplementing it * here. */ private static Class<?> getEnclosingClass(Class<?> declaringClass) { Class<?> result = null; String className = declaringClass.getName(); int index = className.indexOf('$'); if (index != -1) { String ecn = className.substring(0, index); try { result = Class.forName(ecn); } catch (ClassNotFoundException e) { Logger.getLogger(ClassHelper.class).error(e.getMessage(),e); } } return result; }
private Object invokeMethod(Annotation test, String methodName) { Object result = null; try { // Note: we should cache methods already looked up Method m = test.getClass().getMethod(methodName); result = m.invoke(test); } catch (Exception e) { Logger.getLogger(JDK15TagFactory.class).error(e.getMessage(), e); } return result; } }
/** * Tests setting a partial logger name (a hierarchy scope) */ private static void testUserLoggerSetHierarchy() { Properties props= new Properties(); ByteArrayOutputStream out1= new ByteArrayOutputStream(); ByteArrayOutputStream err1= new ByteArrayOutputStream(); PrintStream out2= new PrintStream(out1); PrintStream err2= new PrintStream(err1); props.put("log4testng.logger.java.lang", "DEBUG"); testInitialize(props, out2, err2); Logger strLogger= Logger.getLogger(String.class); strLogger.trace("trace should not appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.debug("debug should appear"); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [DEBUG] debug should appear")); Assert.assertEquals(err1.toString(), ""); }
/** * Test setting the root logger level */ private static void testRootLoggerSet() { Properties props= new Properties(); ByteArrayOutputStream out1= new ByteArrayOutputStream(); ByteArrayOutputStream err1= new ByteArrayOutputStream(); PrintStream out2= new PrintStream(out1); PrintStream err2= new PrintStream(err1); props.put("log4testng.rootLogger", "DEBUG"); testInitialize(props, out2, err2); Logger strLogger= Logger.getLogger(String.class); strLogger.trace("trace should appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.debug("debug should appear"); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [DEBUG] debug should appear")); Assert.assertEquals(err1.toString(), ""); }
/** * Test setting a user logger level */ private static void testUserLoggerSet() { Properties props= new Properties(); ByteArrayOutputStream out1= new ByteArrayOutputStream(); ByteArrayOutputStream err1= new ByteArrayOutputStream(); PrintStream out2= new PrintStream(out1); PrintStream err2= new PrintStream(err1); props.put("log4testng.logger.java.lang.String", "DEBUG"); testInitialize(props, out2, err2); Logger strLogger= Logger.getLogger(String.class); strLogger.trace("trace should not appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.debug("debug should appear"); int outLength= out1.toString().length(); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [DEBUG] debug should appear")); Assert.assertEquals(err1.toString(), ""); Logger classLogger= Logger.getLogger(Class.class); classLogger.debug("debug should not appear"); Assert.assertEquals(out1.toString().length(), outLength); Assert.assertEquals(err1.toString(), ""); classLogger.warn("warn should appear"); Assert.assertTrue(out1.toString().contains("[java.lang.Class] [WARN] warn should appear")); Assert.assertEquals(err1.toString(), ""); }
/** Tests setting a partial logger name (a hierarchy scope) */ private static void testUserLoggerSetHierarchy() { Properties props = new Properties(); ByteArrayOutputStream out1 = new ByteArrayOutputStream(); ByteArrayOutputStream err1 = new ByteArrayOutputStream(); PrintStream out2 = new PrintStream(out1); PrintStream err2 = new PrintStream(err1); props.put("log4testng.logger.java.lang", "DEBUG"); testInitialize(props, out2, err2); Logger strLogger = Logger.getLogger(String.class); strLogger.trace("trace should not appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.debug("debug should appear"); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [DEBUG] debug should appear")); Assert.assertEquals(err1.toString(), ""); }
@Override public XmlSuite parse(String currentFile, InputStream inputStream, boolean loadClasses) { XmlSuite result = null; try { result = parse2(currentFile, inputStream, loadClasses); } catch (Exception e) { Logger.getLogger(DomXmlParser.class).error(e.getMessage(), e); } return result; }
/** Test setting the root logger level */ private static void testRootLoggerSet() { Properties props = new Properties(); ByteArrayOutputStream out1 = new ByteArrayOutputStream(); ByteArrayOutputStream err1 = new ByteArrayOutputStream(); PrintStream out2 = new PrintStream(out1); PrintStream err2 = new PrintStream(err1); props.put("log4testng.rootLogger", "DEBUG"); testInitialize(props, out2, err2); Logger strLogger = Logger.getLogger(String.class); strLogger.trace("trace should appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.debug("debug should appear"); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [DEBUG] debug should appear")); Assert.assertEquals(err1.toString(), ""); }
testInitialize(props, out2, err2); Logger strLogger= Logger.getLogger(String.class); strLogger.trace("trace should not appear"); Assert.assertEquals(out1.toString(), "");
private void setProperty(Object object, String name, Object value) { String methodName = toCamelCaseSetter(name); Method foundMethod = null; for (Method m : object.getClass().getDeclaredMethods()) { if (m.getName().equals(methodName)) { foundMethod = m; break; } } if (foundMethod != null) { try { Class<?> type = foundMethod.getParameterTypes()[0]; if (type == Boolean.class || type == boolean.class) { foundMethod.invoke(object, Boolean.parseBoolean(value.toString())); } else if (type == Integer.class || type == int.class) { foundMethod.invoke(object, Integer.parseInt(value.toString())); } else { foundMethod.invoke(object, value.toString()); } } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException e) { Logger.getLogger(DomUtil.class).error(e.getMessage(), e); } } }
/** Test setting a user logger level */ private static void testUserLoggerSet() { Properties props = new Properties(); ByteArrayOutputStream out1 = new ByteArrayOutputStream(); ByteArrayOutputStream err1 = new ByteArrayOutputStream(); PrintStream out2 = new PrintStream(out1); PrintStream err2 = new PrintStream(err1); props.put("log4testng.logger.java.lang.String", "DEBUG"); testInitialize(props, out2, err2); Logger strLogger = Logger.getLogger(String.class); strLogger.trace("trace should not appear"); Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.debug("debug should appear"); int outLength = out1.toString().length(); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [DEBUG] debug should appear")); Assert.assertEquals(err1.toString(), ""); Logger classLogger = Logger.getLogger(Class.class); classLogger.debug("debug should not appear"); Assert.assertEquals(out1.toString().length(), outLength); Assert.assertEquals(err1.toString(), ""); classLogger.warn("warn should appear"); Assert.assertTrue(out1.toString().contains("[java.lang.Class] [WARN] warn should appear")); Assert.assertEquals(err1.toString(), ""); }
Logger.getLogger(ConversionUtils.class).error(ex.getMessage(), ex);
testInitialize(props, out2, err2); Logger strLogger = Logger.getLogger(String.class); strLogger.trace("trace should not appear"); Assert.assertEquals(out1.toString(), "");
@Override public int compareTo(@Nonnull Object o) { int result = 0; try { SuiteResult other = (SuiteResult) o; String n1 = getTestContext().getName(); String n2 = other.getTestContext().getName(); result = n1.compareTo(n2); } catch (Exception ex) { ex.printStackTrace(); Logger.getLogger(SuiteResult.class).error(ex.getMessage(), ex); } return result; }
Logger.getLogger(ThreadUtil.class).error(handled.getMessage(), handled); Thread.currentThread().interrupt(); } finally {
/** Create one worker per node and execute them. */ private void runNodes(List<T> freeNodes) { List<IWorker<T>> workers = m_factory.createWorkers(freeNodes); mapNodeToWorker(workers, freeNodes); for (int ix = 0; ix < workers.size(); ix++) { IWorker<T> worker = workers.get(ix); mapNodeToParent(freeNodes, ix); setStatus(worker, Status.RUNNING); try { execute(worker); } catch (Exception ex) { Logger.getLogger(GraphThreadPoolExecutor.class).error(ex.getMessage(), ex); } } }
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (!m_validate && !m_hasWarn) { Logger.getLogger(TestNGContentHandler.class).warn("It is strongly recommended to add " + "\"<!DOCTYPE suite SYSTEM \"http://testng.org/testng-1.0.dtd\" >\" at the top of your file, " + "otherwise TestNG may fail or not work as expected.");
throws SAXException { if (!m_validate && !m_hasWarn) { Logger.getLogger(TestNGContentHandler.class) .warn( "It is strongly recommended to add "
Logger.getLogger(Main.class).error(e.getMessage(), e);
HtmlHelper.generateStylesheet(outputDirectory); } catch (IOException e) { Logger.getLogger(SuiteHTMLReporter.class).error(e.getMessage(), e);