Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [riena-dev] Test friendly LOGGER pattern

One more thing to consider:

- In this case: LoggerUtils.getLogger(Activator.getDefault(),
ImageStore.class);  we would need two LoggerUtils implementaions,
because Activator.getDefault() can be either from core (RienaPlugin,
RienaActivator) or from UI (AbstractRienaUIPlugin)

- in the other case we would have three copies of the boilerplate code
in RienaPlugin, RienaActivator, AbstractRienaUIPlugin.

I'm wondering is there a difference between RienaPlugin and
RienaActivator? If we only had one of those, both cases would need two
copies ;-)

Otherwise the first case is a little better (one copy less).

Thinking aloud,
Elias.



On Thu, Mar 5, 2009 at 11:24 PM, Stefan Liebig
<Stefan.Liebig@xxxxxxxxxxxx> wrote:
> This is definitely shorter, but it has the downside of putting boiler plate
> code (the elsewhere code) into each bundles activator.
> Maintenance of this code gets more difficult.
>
> So, I personally would prefer this pattern:
>     private final static Logger LOGGER =
> LoggerUtil.getLogger(Activator.getDefault(), ImageStore.class);
>
> Tschüß,
> Stefan
>
> Elias Volanakis wrote:
>
> 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
>
>
>
> _______________________________________________
> riena-dev mailing list
> riena-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/riena-dev
>
>



-- 
Elias Volanakis
Technical Lead
Innoopract (EclipseSource)
351 NW 12th Avenue
Portland, Oregon 97209

elias@xxxxxxxxxxxxxxxxx
evolanakis@xxxxxxxxxxxxxx
Tel: +1-503-552-1457
Fax: +1-503-715-4915
Mobile: +1-503-929-5537
---
Innoopract is becoming EclipseSource - www.eclipsesource.com


Back to the top