Skip to content

Commit

Permalink
Use constructor injection
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Nov 9, 2024
1 parent ad93844 commit 441f989
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ public class AsciidoctorConverterDoxiaParser extends AbstractTextParser {

private static final Logger logger = LoggerFactory.getLogger(AsciidoctorConverterDoxiaParser.class);

private final MavenProject mavenProject;
private final SiteConversionConfigurationParser siteConfigParser;
private final LogHandlerFactory logHandlerFactory;
private final SiteConverterDecorator siteConverter;

@Inject
private MavenProject mavenProject;
@Inject
private SiteConversionConfigurationParser siteConfigParser;
@Inject
private LogHandlerFactory logHandlerFactory;
@Inject
private SiteConverterDecorator siteConverter;
public AsciidoctorConverterDoxiaParser(MavenProject mavenProject,
SiteConversionConfigurationParser siteConfigParser,
LogHandlerFactory logHandlerFactory,
SiteConverterDecorator siteConverter) {
this.mavenProject = mavenProject;
this.siteConfigParser = siteConfigParser;
this.logHandlerFactory = logHandlerFactory;
this.siteConverter = siteConverter;
}

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static org.asciidoctor.maven.site.AsciidoctorConverterDoxiaParser.ROLE_HINT;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.codehaus.plexus.util.ReflectionUtils.setVariableValueInObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -264,19 +263,19 @@ private AsciidoctorConverterDoxiaParser mockAsciidoctorDoxiaParser() {

@SneakyThrows
private AsciidoctorConverterDoxiaParser mockAsciidoctorDoxiaParser(String configuration) {
AsciidoctorConverterDoxiaParser parser = new AsciidoctorConverterDoxiaParser();
setVariableValueInObject(parser, "mavenProject", createMockMavenProject(configuration));
setVariableValueInObject(parser, "siteConfigParser", new SiteConversionConfigurationParser(new SiteBaseDirResolver()));
setVariableValueInObject(parser, "logHandlerFactory", new LogHandlerFactory());
setVariableValueInObject(parser, "siteConverter", new SiteConverterDecorator());
return parser;
return new AsciidoctorConverterDoxiaParser(
createMockMavenProject(configuration),
new SiteConversionConfigurationParser(new SiteBaseDirResolver()),
new LogHandlerFactory(),
new SiteConverterDecorator()
);
}

private Sink createSinkMock() {
return new TextProviderSink();
}

class TextProviderSink extends AbstractTextSink {
static class TextProviderSink extends AbstractTextSink {
String text;

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package org.asciidoctor.maven.site;

import java.io.File;

import org.asciidoctor.Asciidoctor;
import org.asciidoctor.maven.log.LogHandler;
import org.asciidoctor.maven.log.LogRecordFormatter;
import org.asciidoctor.maven.log.MemoryLogHandler;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.slf4j.Logger;

import java.io.File;

/**
* Factory to parse and create {@link MemoryLogHandler} in order to handle
* issues during processing.
*
* @author abelsromero
* @since 3.1.1
*/
public class LogHandlerFactory {

public LogHandler getConfiguration(Xpp3Dom siteConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.asciidoctor.maven.site.HeadParser;
import org.asciidoctor.maven.site.HeaderMetadata;
import org.asciidoctor.maven.site.LogHandlerFactory;
import org.asciidoctor.maven.site.SiteConversionConfigurationParser;
import org.asciidoctor.maven.site.SiteConversionConfiguration;
import org.asciidoctor.maven.site.SiteConversionConfigurationParser;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.Xpp3Dom;
Expand Down Expand Up @@ -48,12 +48,18 @@ public class AsciidoctorAstDoxiaParser extends AbstractTextParser {

private static final Logger logger = LoggerFactory.getLogger(AsciidoctorAstDoxiaParser.class);

private final MavenProject mavenProject;
private final SiteConversionConfigurationParser siteConfigParser;
private final LogHandlerFactory logHandlerFactory;

@Inject
private MavenProject mavenProject;
@Inject
private SiteConversionConfigurationParser siteConfigParser;
@Inject
private LogHandlerFactory logHandlerFactory;
public AsciidoctorAstDoxiaParser(MavenProject mavenProject,
SiteConversionConfigurationParser siteConfigParser,
LogHandlerFactory logHandlerFactory) {
this.mavenProject = mavenProject;
this.siteConfigParser = siteConfigParser;
this.logHandlerFactory = logHandlerFactory;
}

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static org.asciidoctor.maven.site.parser.processors.test.TestNodeProcessorFactory.createSink;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.codehaus.plexus.util.ReflectionUtils.setVariableValueInObject;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -250,11 +249,11 @@ static AsciidoctorAstDoxiaParser mockAsciidoctorDoxiaParser() {

@SneakyThrows
static AsciidoctorAstDoxiaParser mockAsciidoctorDoxiaParser(String configuration) {
AsciidoctorAstDoxiaParser parser = new AsciidoctorAstDoxiaParser();
setVariableValueInObject(parser, "mavenProject", createMockMavenProject(configuration));
setVariableValueInObject(parser, "siteConfigParser", new SiteConversionConfigurationParser(new SiteBaseDirResolver()));
setVariableValueInObject(parser, "logHandlerFactory", new LogHandlerFactory());
return parser;
return new AsciidoctorAstDoxiaParser(
createMockMavenProject(configuration),
new SiteConversionConfigurationParser(new SiteBaseDirResolver()),
new LogHandlerFactory()
);
}
}
}

0 comments on commit 441f989

Please sign in to comment.