Skip to content

Commit

Permalink
feat(objectionary#2674):added tests in VerifyMojoTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanich96 committed Dec 22, 2023
1 parent b44d01a commit bd81ca0
Showing 1 changed file with 53 additions and 7 deletions.
60 changes: 53 additions & 7 deletions eo-maven-plugin/src/test/java/org/eolang/maven/VerifyMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.yegor256.xsline.Xsline;
import java.nio.file.Path;
import org.cactoos.io.ResourceOf;
import org.eolang.maven.log.CaptureLogs;
import org.eolang.maven.log.Logs;
import org.eolang.maven.util.HmBase;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -41,12 +43,8 @@
* Test cases for {@link VerifyMojo}.
*
* @since 0.31.0
* @todo #2546:90min Add test that checks the message of exception in case of
* warning, error and critical in xmir. According to
* eo-parser/src/main/resources/org/eolang/parser/fail-on-critical.xsl it includes
* filename and line inside.
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
@SuppressWarnings({"PMD.AvoidDuplicateLiterals", "PMD.TooManyMethods"})
class VerifyMojoTest {

@Test
Expand All @@ -60,7 +58,10 @@ void doesNotFailWithNoErrorsAndWarnings(@TempDir final Path temp) {
}

@Test
void detectsErrorsSuccessfully(@TempDir final Path temp) {
@CaptureLogs
void detectsErrorsSuccessfully(
@TempDir final Path temp,
final Logs out) {
Assertions.assertThrows(
IllegalStateException.class,
() -> new FakeMaven(temp)
Expand All @@ -73,10 +74,47 @@ void detectsErrorsSuccessfully(@TempDir final Path temp) {
.execute(new FakeMaven.Verify()),
"Program with noname attributes should have failed or error, but it didn't"
);
Assertions.assertTrue(
out.captured().stream().anyMatch(
log -> log.contains(
"Errors identified"
)
),
"The program should exit with an error from 'fail-on-errors.xsl'."
);
}

@Test
void detectsWarningWithCorrespondingFlag(@TempDir final Path temp) {
@CaptureLogs
void detectsCriticalErrorsSuccessfully(
@TempDir final Path temp,
final Logs out) {
Assertions.assertThrows(
IllegalStateException.class,
() -> new FakeMaven(temp)
.withProgram(
"+package f\n",
"[] > main",
" \"Hello world\""
)
.execute(new FakeMaven.Verify()),
"Wrong program should have failed or error, but it didn't"
);
Assertions.assertTrue(
out.captured().stream().anyMatch(
log -> log.contains(
"Critical error identified"
)
),
"The program should exit with an error from 'fail-on-critical.xsl'."
);
}

@Test
@CaptureLogs
void detectsWarningWithCorrespondingFlag(
@TempDir final Path temp,
final Logs out) {
Assertions.assertThrows(
IllegalStateException.class,
() -> new FakeMaven(temp)
Expand All @@ -90,6 +128,14 @@ void detectsWarningWithCorrespondingFlag(@TempDir final Path temp) {
.execute(new FakeMaven.Verify()),
"Program with sparse decorated object should have failed on warning, but it didn't"
);
Assertions.assertTrue(
out.captured().stream().anyMatch(
log -> log.contains(
"Warnings identified"
)
),
"The program should exit with an error from 'fail-on-warnings.xsl'."
);
}

@Test
Expand Down

0 comments on commit bd81ca0

Please sign in to comment.