[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [riena-dev] Test friendly LOGGER pattern
|
Nice.
Along those lines: how about making getLogger(...) static and moving the logic into there:
private final static Logger LOGGER = Activator.getLogger(FooClass.class);
// elsewhere:
class Activator {
public static Logger getLogger(Class clazz) {
if(getDefault() == null) {
return ... normal logger...
}
return new ConsoleLogger(clazz.getName());
}
}
Tschuess,
Elias.
On Thu, Mar 5, 2009 at 1:37 AM, Stefan Liebig
<Stefan.Liebig@xxxxxxxxxxxx> wrote:
How about something like this:
private final static Logger LOGGER =
LoggerUtil.getLogger(Activator.getDefault(), ImageStore.class);
Looks much nicer to me. ;-)
Tschüß,
Stefan
Elias Volanakis wrote:
Just a quick tip:
If you use static LOGGER fields, I recommend using the pattern
(b) below. It avoids a NPE exception when calling
Activator.getDefault().getLogger(), which usually happens when running
test suites as "plain" junit tests.
(a) Problematic with Junit:
public final class MyClass {
private
static final Logger LOGGER =
Activator.getDefault().getLogger(ImageStore.class);
(b) Works well with Junit:
public final class MyClass {
private
static final Logger LOGGER;
static
{
if
(Activator.getDefault() != null) {
LOGGER
= Activator.getDefault().getLogger(MyClass.class);
}
else {
LOGGER
= new ConsoleLogger(MyClass.class.getName());
}
}
I know that some test cases must be run as "plug-in" tests, but
I usually run individual test cases for stuff I'm working on as
"regular" unit-tests, because they start much faster :-)
Viele Gruesse,
Elias.
_______________________________________________
riena-dev mailing list
riena-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/riena-dev