Skip to content
Permalink
Browse files

solved issues with injecting decorators

  • Loading branch information...
maciejmikosik committed Jan 4, 2018
2 parents 19258d2 + 8b312e3 commit 5f676581ce1ba5276ee6804dcd885e0126c18f12
@@ -9,7 +9,7 @@
import static org.logbuddy.bind.StdioBinder.stdioBinder;
import static org.logbuddy.decorator.CachingDecorator.caching;
import static org.logbuddy.decorator.ComposedDecorator.compose;
import static org.logbuddy.decorator.InjectingLoggerDecorator.injecting;
import static org.logbuddy.decorator.InjectingDecorator.injecting;
import static org.logbuddy.decorator.InvocationDecorator.invocationDecorator;
import static org.logbuddy.decorator.TraversingDecorator.traversing;
import static org.logbuddy.logger.AsynchronousLogger.asynchronous;
@@ -256,7 +256,7 @@ public static void decorator_caching(Decorator decorator, Object object) {

}

public static void decorator_inject_logger() {
public static void decorator_injecting() {
class Service {
Logger logger = noLogger();

@@ -284,8 +284,8 @@ If you decorate same object again, it returns same result as first time.
cachingDecorator.decorate(object),
cachingDecorator.decorate(object));

`InjectingLoggerDecorator` allows you to manually log messages in production code.
It injects given `Logger` to fields of matching type.
`InjectingDecorator` allows you to manually log messages in production code.
It injects given `Logger` to fields of that type.
It is wise to initialize this field with instance of `NoLogger` to prevent `NullPointerException` in case instance is not decorated.

class Service {
@@ -303,8 +303,6 @@ It is wise to initialize this field with instance of `NoLogger` to prevent `Null
-------------- prints --------------
adhoc message

`InjectingDecoratorDecorator` does similar thing, injecting given `Decorator`.

`ComposedDecorator` lets you combine two decorators into one.
For example you want to combine functionality of `InvocationDecorator` with `InjectingLoggerDecorator`.

@@ -8,8 +8,7 @@
import org.logbuddy.bind.StdioBinder;
import org.logbuddy.decorator.CachingDecorator;
import org.logbuddy.decorator.ComposedDecorator;
import org.logbuddy.decorator.InjectingDecoratorDecorator;
import org.logbuddy.decorator.InjectingLoggerDecorator;
import org.logbuddy.decorator.InjectingDecorator;
import org.logbuddy.decorator.InvocationDecorator;
import org.logbuddy.decorator.NoDecorator;
import org.logbuddy.decorator.TraversingDecorator;
@@ -60,8 +59,7 @@
InvocationDecorator.class,
ComposedDecorator.class,
NoDecorator.class,
InjectingLoggerDecorator.class,
InjectingDecoratorDecorator.class,
InjectingDecorator.class,
TraversingDecorator.class,
CachingDecorator.class);
public List<Class<?>> bind = asList(
@@ -10,16 +10,16 @@
import org.logbuddy.Decorator;
import org.logbuddy.Logger;

public class InjectingLoggerDecorator implements Decorator {
public class InjectingDecorator implements Decorator {
private final Logger logger;

private InjectingLoggerDecorator(Logger logger) {
private InjectingDecorator(Logger logger) {
this.logger = logger;
}

public static Decorator injecting(Logger logger) {
check(logger != null);
return new InjectingLoggerDecorator(logger);
return new InjectingDecorator(logger);
}

public <T> T decorate(T decorable) {

This file was deleted.

@@ -1,7 +1,7 @@
package org.logbuddy.decorator;

import static java.lang.String.format;
import static org.logbuddy.decorator.InjectingLoggerDecorator.injecting;
import static org.logbuddy.decorator.InjectingDecorator.injecting;
import static org.testory.Testory.given;
import static org.testory.Testory.givenTest;
import static org.testory.Testory.thenEqual;
@@ -15,7 +15,7 @@
import org.logbuddy.LogBuddyException;
import org.logbuddy.Logger;

public class TestInjectingLoggerDecorator {
public class TestInjectingDecorator {
private Decorable decorable;
private Decorator injecting;
private Logger logger;

This file was deleted.

0 comments on commit 5f67658

Please sign in to comment.
You can’t perform that action at this time.