Yeah, I mock the log object in my unit tests to get around the fact that there is no application context active. It looks like this, and seems to work ok:
| package org.uscm.crs.misc; | | import org.jboss.seam.log.Log; | import org.jboss.seam.log.Logging; | | public class MockSeamLogger implements Log { | | | private Log log; | | public MockSeamLogger() { | log = Logging.getLog(MockSeamLogger.class); | } | | public MockSeamLogger(Class clazz) { | log = Logging.getLog(clazz); | } | | | private Object clean(Object object) { | if (object instanceof String) { | String string = (String) object; | return string.replace("#{", "{"); | } | return object; | } | | public void debug(Object object, Object... params) { | log.debug(clean(object), params); | } | | | public void debug(Object object, Throwable t, Object... params) { | log.debug(clean(object), t, params); | | } | | public void error(Object object, Object... params) { | log.error(clean(object), params); | } | | public void error(Object object, Throwable t, Object... params) { | log.error(clean(object), t, params); | | } | | public void fatal(Object object, Object... params) { | log.fatal(clean(object), params); | } | | public void fatal(Object object, Throwable t, Object... params) { | log.fatal(clean(object), t, params); | | } | | public void info(Object object, Object... params) { | log.info(clean(object), params); | } | | public void info(Object object, Throwable t, Object... params) { | log.info(clean(object), t, params); | | } | | public boolean isDebugEnabled() { | return true; | } | | public boolean isErrorEnabled() { | return true; | } | | public boolean isFatalEnabled() { | return true; | } | | public boolean isInfoEnabled() { | return true; | } | | public boolean isTraceEnabled() { | return true; | } | | public boolean isWarnEnabled() { | return true; | } | | public void trace(Object object, Object... params) { | log.trace(clean(object), params); | } | | public void trace(Object object, Throwable t, Object... params) { | log.trace(clean(object), t, params); | } | | public void warn(Object object, Object... params) { | log.warn(clean(object), params); | } | | public void warn(Object object, Throwable t, Object... params) { | log.warn(clean(object), t); | } | | } | I'm definitely interested to hear if anyone else has found useful patterns for unit testing. I'm wondering if it'd be worth it to simply set up the Application context manually; it might be lightweight enough to be reasonable in a unit test. View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4045259#4045259 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4045259 _______________________________________________ jboss-user mailing list jboss-user@lists.jboss.org https://lists.jboss.org/mailman/listinfo/jboss-user