Skip to content

Commit

Permalink
fix(objectionary#2681): added exception in TransipleMojo + test
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanich96 committed Dec 11, 2023
1 parent ee760d0 commit d2ee84a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
12 changes: 10 additions & 2 deletions eo-maven-plugin/src/main/java/org/eolang/maven/TranspileMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,23 @@ public void exec() throws IOException {
* @throws java.io.IOException If any issues with I/O
*/
private int transpile(final ForeignTojo tojo) throws IOException {
final int saved;
final Path file = tojo.verified();
final Path file;
try {
file = tojo.verified();
} catch (final IllegalStateException exception) {
throw new IllegalStateException(
"You should check that verify goal of the plugin was run first",
exception
);
}
final XML input = new XMLDocument(file);
final String name = input.xpath("/program/@name").get(0);
final Place place = new Place(name);
final Path target = place.make(
this.targetDir.toPath().resolve(TranspileMojo.DIR),
TranspileMojo.EXT
);
final int saved;
if (
target.toFile().exists()
&& target.toFile().lastModified() >= file.toFile().lastModified()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -35,11 +36,14 @@
import org.cactoos.text.Randomized;
import org.cactoos.text.TextOf;
import org.eolang.jucs.ClasspathSource;
import org.eolang.maven.log.CaptureLogs;
import org.eolang.maven.log.Logs;
import org.eolang.maven.util.HmBase;
import org.eolang.xax.XaxStory;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.io.FileMatchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
Expand All @@ -50,7 +54,7 @@
*
* @since 0.1
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"})
final class TranspileMojoTest {

/**
Expand Down Expand Up @@ -218,6 +222,28 @@ void transpilesAndCleansGarbageFromDirtyDependency(@TempDir final Path temp)
);
}

@Test
@CaptureLogs
void transpilesThrowExceptionIfWasNotVerified(
@TempDir final Path temp, final Logs out) throws IOException {
final FakeMaven maven = new FakeMaven(temp);
maven.withHelloWorld();
Assertions.assertThrows(
IllegalStateException.class,
() -> maven
.execute(ParseMojo.class)
.execute(OptimizeMojo.class)
.execute(ShakeMojo.class)
.execute(TranspileMojo.class)
);
final Collection<String> logs = out.captured();
final String message = "You should check that verify goal of the plugin was run first";
Assertions.assertTrue(
logs.stream().anyMatch(log -> log.contains(message)),
"Should throw an exception if VerifyMojo wasn't run before TranspileMojo"
);
}

/**
* Get all classes in directory.
* @param root Directory to get classes from.
Expand Down

0 comments on commit d2ee84a

Please sign in to comment.