Skip to content

Commit

Permalink
Removed nested class in Logbook
Browse files Browse the repository at this point in the history
  • Loading branch information
Willi Schönborn committed May 1, 2016
1 parent bf8a605 commit 7a9f815
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 60 deletions.
97 changes: 42 additions & 55 deletions logbook-api/src/main/java/org/zalando/logbook/Logbook.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* #L%
*/

import com.google.gag.annotation.remark.Hack;
import lombok.Singular;

import javax.annotation.Nullable;
Expand All @@ -37,60 +36,48 @@ static Logbook create() {
return builder().build();
}

static Creator.Builder builder() {
return Creator.builder();
@lombok.Builder(builderClassName = "Builder")
static Logbook create(
@Nullable final Predicate<RawHttpRequest> condition,
@Singular final List<QueryObfuscator> queryObfuscators,
@Singular final List<HeaderObfuscator> headerObfuscators,
@Singular final List<BodyObfuscator> bodyObfuscators,
@Singular final List<RequestObfuscator> requestObfuscators,
@Singular final List<ResponseObfuscator> responseObfuscators,
@Nullable final HttpLogFormatter formatter,
@Nullable final HttpLogWriter writer) {

final LogbookFactory factory = LogbookFactory.INSTANCE;

final QueryObfuscator queryObfuscator = queryObfuscators.stream()
.reduce(QueryObfuscator::merge)
.orElse(null);

final HeaderObfuscator headerObfuscator = headerObfuscators.stream()
.reduce(HeaderObfuscator::merge)
.orElse(null);

final BodyObfuscator bodyObfuscator = bodyObfuscators.stream()
.reduce(BodyObfuscator::merge)
.orElse(null);

final RequestObfuscator requestObfuscator = requestObfuscators.stream()
.reduce(RequestObfuscator::merge)
.orElse(null);

final ResponseObfuscator responseObfuscator = responseObfuscators.stream()
.reduce(ResponseObfuscator::merge)
.orElse(null);

return factory.create(
condition,
queryObfuscator,
headerObfuscator,
bodyObfuscator,
requestObfuscator,
responseObfuscator,
formatter,
writer);
}

@Hack("The Lombok IDEA plugin doesn't like @Builder on static interface methods")
final class Creator {

Creator() {
// package private so we can trick code coverage
}

@lombok.Builder(builderClassName = "Builder")
static Logbook create(
@Nullable final Predicate<RawHttpRequest> condition,
@Singular final List<QueryObfuscator> queryObfuscators,
@Singular final List<HeaderObfuscator> headerObfuscators,
@Singular final List<BodyObfuscator> bodyObfuscators,
@Singular final List<RequestObfuscator> requestObfuscators,
@Singular final List<ResponseObfuscator> responseObfuscators,
@Nullable final HttpLogFormatter formatter,
@Nullable final HttpLogWriter writer) {

final LogbookFactory factory = LogbookFactory.INSTANCE;

final QueryObfuscator queryObfuscator = queryObfuscators.stream()
.reduce(QueryObfuscator::merge)
.orElse(null);

final HeaderObfuscator headerObfuscator = headerObfuscators.stream()
.reduce(HeaderObfuscator::merge)
.orElse(null);

final BodyObfuscator bodyObfuscator = bodyObfuscators.stream()
.reduce(BodyObfuscator::merge)
.orElse(null);

final RequestObfuscator requestObfuscator = requestObfuscators.stream()
.reduce(RequestObfuscator::merge)
.orElse(null);

final ResponseObfuscator responseObfuscator = responseObfuscators.stream()
.reduce(ResponseObfuscator::merge)
.orElse(null);

return factory.create(
condition,
queryObfuscator,
headerObfuscator,
bodyObfuscator,
requestObfuscator,
responseObfuscator,
formatter,
writer);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ public void shouldUseRequestURIConstructor() {
new RequestURI();
}

@Test
public void shouldUseCreatorConstructor() {
new Logbook.Creator();
}

@Test
public void shouldUseHeadersConstructor() {
new BaseHttpMessage.Headers();
Expand Down

0 comments on commit 7a9f815

Please sign in to comment.