jueves, 30 de agosto de 2007

Pruebas de unidad en Jboss Seam, implementar org.jboss.seam.log.Log con org.apache.commons.logging.Log

Si intentamos probar un componente de Jboss Seam en aislamiento/unidad y este componente tiene una Log inyectado por Seam, tendremos un nullexception al lanzar la prueba, aquí dejo un ejemplo en el que creamos una clase que implementa org.jboss.seam.log.Log y que accede a org.apache.commons.logging.Log

public class BeanTest {

@Test
public void testBean(){
Bean bean=new Bean();
bean.log=new Logger();
bean.run();
}

}
class Logger implements org.jboss.seam.log.Log{
Log log = LogFactory.getLog(BeanTest.class);

public boolean isDebugEnabled() {
return log.isDebugEnabled();
}

public boolean isErrorEnabled() {
return log.isErrorEnabled();
}

public boolean isFatalEnabled() {
return log.isFatalEnabled();
}

public boolean isInfoEnabled() {
return log.isInfoEnabled();

}

public boolean isTraceEnabled() {
return log.isTraceEnabled();
}

public boolean isWarnEnabled() {
return log.isWarnEnabled();
}

public void trace(Object object, Object... params) {
log.trace(object);
}

public void trace(Object object, Throwable t, Object... params) {
log.trace(object,t);
}

public void debug(Object object, Object... params) {
log.debug(object);
}

public void debug(Object object, Throwable t, Object... params) {
log.debug(object,t);
}

public void info(Object object, Object... params) {
log.info(object);
}

public void info(Object object, Throwable t, Object... params) {
log.info(object,t);

}

public void warn(Object object, Object... params) {
log.warn(object);
}

public void warn(Object object, Throwable t, Object... params) {
log.warn(object,t);

}

public void error(Object object, Object... params) {
log.error(object);

}

public void error(Object object, Throwable t, Object... params) {
log.error(object,t);
}

public void fatal(Object object, Object... params) {
log.fatal(object);
}

public void fatal(Object object, Throwable t, Object... params) {
log.fatal(object,t);
}
}

No hay comentarios: