Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
add another rule for the integration test to find
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie committed Jan 31, 2017
1 parent e2fe22c commit 9accb06
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void execute(
try {
rule.execute(raml);
} catch (final LintCheckerException e) {
throw new MojoExecutionException("Lint checker rule failed", e);
throw new MojoExecutionException("Lint checker rule failed for rule " + rule.getClass().getSimpleName(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class LintCheckerMojoDelegateTest {
@Mock
private PathsProvider pathsProvider;


@InjectMocks
private LintCheckerMojoDelegate lintCheckerMojoDelegate;

Expand Down Expand Up @@ -101,10 +100,9 @@ public void shouldThrowMojoExecutionExceptionAIfExecutingARuleFails() throws Exc
fail();
} catch (final MojoExecutionException expected) {
assertThat(expected.getCause(), is(lintCheckerException));
assertThat(expected.getMessage(), is("Lint checker rule failed"));
assertThat(expected.getMessage(), is("Lint checker rule failed for rule " + lintCheckRule_1.getClass().getSimpleName()));
}

verify(lintCheckRule_1).execute(raml_1);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@
import static org.junit.Assert.assertThat;

import uk.gov.justice.raml.maven.generator.BetterAbstractMojoTestCase;
import uk.gov.justice.raml.maven.lintchecker.rules.FailingLintCheckRule;
import uk.gov.justice.raml.maven.lintchecker.rules.SucceedingLintCheckRule;

import java.io.File;

import org.apache.maven.plugin.MojoExecutionException;
import org.junit.Test;

public class LintCheckerMojoTest extends BetterAbstractMojoTestCase {

public void testShouldFindLintCheckMojo() throws Exception {

public void testFindAllMojosUnderTheSourceDirectory() throws Exception {

final File pom = getTestFile("src/test/resources/lint-check/pom.xml");
final LintCheckerMojo mojo = (LintCheckerMojo) lookupConfiguredMojo(pom, "lint-check");

assertThat(mojo.rules.length, is(2));
assertThat(mojo.rules[0], is(instanceOf(SucceedingLintCheckRule.class)));
assertThat(mojo.rules[1], is(instanceOf(FailingLintCheckRule.class)));
}

public void testRunAllRulesAndFailIfTheRuleFails() throws Exception {

final File pom = getTestFile("src/test/resources/lint-check/pom.xml");
final LintCheckerMojo mojo = (LintCheckerMojo) lookupConfiguredMojo(pom, "lint-check");
Expand All @@ -21,7 +35,7 @@ public void testShouldFindLintCheckMojo() throws Exception {
mojo.execute();
fail();
} catch (final MojoExecutionException expected) {
assertThat(expected.getMessage(), is("Lint checker rule failed"));
assertThat(expected.getMessage(), is("Lint checker rule failed for rule FailingLintCheckRule"));
assertThat(expected.getCause(), is(instanceOf(LintCheckerException.class)));
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ public void shouldThrowAMojoFailureExceptionIfFindingPathsFails() throws Excepti
final String[] includes = {"include_1"};
final String[] excludes = {"exclude_1"};

final Collection<Path> paths = singletonList(get("."));

when(scannerFactory.create()).thenReturn(fileTreeScanner);
when(fileTreeScanner.find(sourceDirectory.toPath(), includes, excludes)).thenThrow(ioException);

Expand All @@ -74,6 +72,5 @@ public void shouldThrowAMojoFailureExceptionIfFindingPathsFails() throws Excepti
assertThat(expected.getCause(), is(ioException));
assertThat(expected.getMessage(), is("Failed to find paths for source directory my-directory"));
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package uk.gov.justice.raml.maven.lintchecker.rules;

import uk.gov.justice.raml.maven.lintchecker.LintCheckRule;
import uk.gov.justice.raml.maven.lintchecker.LintCheckerException;

import org.raml.model.Raml;

public class FailingLintCheckRule implements LintCheckRule {

@Override
public void execute(final Raml raml) throws LintCheckerException {
throw new LintCheckerException("LintCheckRule applied");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package uk.gov.justice.raml.maven.lintchecker.rules;

import uk.gov.justice.raml.maven.lintchecker.LintCheckRule;
import uk.gov.justice.raml.maven.lintchecker.LintCheckerException;

import org.raml.model.Raml;

public class SucceedingLintCheckRule implements LintCheckRule {

@Override
public void execute(final Raml raml) throws LintCheckerException {
// cool
}
}
5 changes: 3 additions & 2 deletions raml-maven-plugin/src/test/resources/lint-check/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
<excludes>
</excludes>
<rules>
<MatchHandersActions implementation = "uk.gov.justice.raml.maven.lintchecker.MockLintCheckRule"/>
<MatchHandersActions implementation = "uk.gov.justice.raml.maven.lintchecker.rules.SucceedingLintCheckRule"/>
<MatchHandersActions implementation = "uk.gov.justice.raml.maven.lintchecker.rules.FailingLintCheckRule"/>
</rules>
</configuration>
</plugin>
</plugins>
</build>
</project>
</project>

0 comments on commit 9accb06

Please sign in to comment.