private void setConfigurable(IConfigurable c) { // compare by reference! if (m_configurable != null && m_configurable != c) { LOGGER.warn("Configurable already set"); } m_configurable = c; }
private void setHookable(IHookable h) { // compare by reference! if (m_hookable != null && m_hookable != h) { LOGGER.warn("Hookable already set"); } m_hookable = h; }
private void setAnnotationTransformer(IAnnotationTransformer t) { // compare by reference! if (m_annotationTransformer != m_defaultAnnoProcessor && m_annotationTransformer != t) { LOGGER.warn("AnnotationTransformer already set"); } m_annotationTransformer = t; }
private void setConfigurable(IConfigurable c) { // compare by reference! if (m_configurable != null && m_configurable != c) { LOGGER.warn("Configurable already set"); } m_configurable = c; }
private void setHookable(IHookable h) { // compare by reference! if (m_hookable != null && m_hookable != h) { LOGGER.warn("Hookable already set"); } m_hookable = h; }
/** * @deprecated Use addListener(ITestNGListener) instead */ // TODO make private @Deprecated public void setAnnotationTransformer(IAnnotationTransformer t) { // compare by reference! if (m_annotationTransformer != m_defaultAnnoProcessor && m_annotationTransformer != t) { LOGGER.warn("AnnotationTransformer already set"); } m_annotationTransformer = t; }
private static <E> void maybeAddListener(Map<Class<? extends E>, E> map, Class<? extends E> type, E value, boolean quiet) { if (map.containsKey(type)) { if (!quiet) { LOGGER.warn("Ignoring duplicate listener : " + type.getName()); } } else { map.put(type, value); } }
public static void setPropertyRealValue(Object instance, String name, Object value) { if (instance == null) { LOGGER.warn("Cannot set property " + name + " with value " + value + ". Targe instance is null"); return; } PropertyDescriptor propDesc = getPropertyDescriptor(instance.getClass(), name); if (propDesc == null) { LOGGER.warn("Cannot set property " + name + " with value " + value + ". Property does not exist"); return; } Method method = propDesc.getWriteMethod(); try { method.invoke(instance, new Object[]{value}); } catch (IllegalAccessException | InvocationTargetException iae) { LOGGER.warn("Cannot set property " + name + " with value " + value + ". Cause " + iae); } }
private static PropertyDescriptor getPropertyDescriptor(Class targetClass, String propertyName) { PropertyDescriptor result = null; if (targetClass == null) { LOGGER.warn("Cannot retrieve property " + propertyName + ". Class is null"); } else { try { BeanInfo beanInfo = Introspector.getBeanInfo(targetClass); PropertyDescriptor[] propDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor propDesc : propDescriptors) { if (propDesc.getName().equals(propertyName)) { result = propDesc; break; } } } catch (IntrospectionException ie) { LOGGER.warn("Cannot retrieve property " + propertyName + ". Cause is: " + ie); } } return result; }
public static Class getPropertyType(Class instanceClass, String propertyName) { if (instanceClass == null) { LOGGER.warn("Cannot retrieve property class for " + propertyName + ". Target instance class is null"); } PropertyDescriptor propDesc = getPropertyDescriptor(instanceClass, propertyName); if (propDesc == null) { return null; } return propDesc.getPropertyType(); }
private static <E> void maybeAddListener( Map<Class<? extends E>, E> map, Class<? extends E> type, E value, boolean quiet) { if (map.containsKey(type)) { if (!quiet) { LOGGER.warn("Ignoring duplicate listener : " + type.getName()); } } else { map.put(type, value); } }
private static PropertyDescriptor getPropertyDescriptor(Class targetClass, String propertyName) { PropertyDescriptor result = null; if (targetClass == null) { LOGGER.warn("Cannot retrieve property " + propertyName + ". Class is null"); } else { try { BeanInfo beanInfo = Introspector.getBeanInfo(targetClass); PropertyDescriptor[] propDescriptors = beanInfo.getPropertyDescriptors(); for (PropertyDescriptor propDesc : propDescriptors) { if (propDesc.getName().equals(propertyName)) { result = propDesc; break; } } } catch (IntrospectionException ie) { LOGGER.warn("Cannot retrieve property " + propertyName + ". Cause is: " + ie); } } return result; }
public static void setPropertyRealValue(Object instance, String name, Object value) { if (instance == null) { LOGGER.warn( "Cannot set property " + name + " with value " + value + ". Targe instance is null"); return; } PropertyDescriptor propDesc = getPropertyDescriptor(instance.getClass(), name); if (propDesc == null) { LOGGER.warn( "Cannot set property " + name + " with value " + value + ". Property does not exist"); return; } Method method = propDesc.getWriteMethod(); try { method.invoke(instance, value); } catch (IllegalAccessException | InvocationTargetException iae) { LOGGER.warn("Cannot set property " + name + " with value " + value + ". Cause " + iae); } } }
public static Class getPropertyType(Class instanceClass, String propertyName) { if (instanceClass == null) { LOGGER.warn( "Cannot retrieve property class for " + propertyName + ". Target instance class is null"); } PropertyDescriptor propDesc = getPropertyDescriptor(instanceClass, propertyName); if (propDesc == null) { return null; } return propDesc.getPropertyType(); }
public static void setProperty(Object instance, String name, String value) { if (instance == null) { LOGGER.warn("Cannot set property " + name + " with value " + value + ". The target instance is null"); return; } Class propClass = getPropertyType(instance.getClass(), name); if (propClass == null) { LOGGER.warn("Cannot set property " + name + " with value " + value + ". Property class could not be found"); return; } Object realValue = Parameters.convertType(propClass, value, name); //TODO: Here the property desc is serched again setPropertyRealValue(instance, name, realValue); }
/** * 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(), ""); }
Assert.assertEquals(out1.toString(), ""); Assert.assertEquals(err1.toString(), ""); strLogger.warn("warn should appear"); int outlength= out1.toString().length(); Assert.assertTrue(out1.toString().startsWith("[java.lang.String] [WARN] warn should appear"));
public static void setProperty(Object instance, String name, String value) { if (instance == null) { LOGGER.warn( "Cannot set property " + name + " with value " + value + ". The target instance is null"); return; } Class propClass = getPropertyType(instance.getClass(), name); if (propClass == null) { LOGGER.warn( "Cannot set property " + name + " with value " + value + ". Property class could not be found"); return; } Object realValue = Parameters.convertType(propClass, value, name); // TODO: Here the property desc is serched again setPropertyRealValue(instance, name, realValue); }
private void addReporter(ReporterConfig reporterConfig) { IReporter instance = reporterConfig.newReporterInstance(); if (instance != null) { addListener(instance); } else { LOGGER.warn("Could not find reporter class : " + reporterConfig.getClassName()); } }
private void addReporter(ReporterConfig reporterConfig) { IReporter instance = reporterConfig.newReporterInstance(); if (instance != null) { addListener(instance); } else { LOGGER.warn("Could not find reporter class : " + reporterConfig.getClassName()); } }