Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Suppress log messages when testing "strict" mode. (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Mar 30, 2022
1 parent 1c164e8 commit 6291ed5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion metafix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dependencies {
implementation "org.metafacture:metamorph:${versions.metafacture}"

testImplementation "nl.jqno.equalsverifier:equalsverifier:${versions.equalsverifier}"
testImplementation "org.mockito:mockito-core:${versions.mockito}"
testImplementation "org.mockito:mockito-inline:${versions.mockito}"
testImplementation "org.mockito:mockito-junit-jupiter:${versions.mockito}"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -390,14 +391,19 @@ public void shouldIncludeLocationAndTextInExecutionException() {
);
}

private void assertStrictness(final Metafix.Strictness strictness, final String fixDef, final Consumer<Supplier<StreamReceiver>> out) {
private void assertStrictness(final Metafix.Strictness strictness, final String fixDef, final boolean stubLogging, final Consumer<Supplier<StreamReceiver>> out) {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_field('before', '')",
fixDef,
"add_field('after', '')"
),
i -> {
i.setStrictness(strictness);
final Metafix.Strictness strictnessSpy = Mockito.spy(strictness);
i.setStrictness(strictnessSpy);

if (stubLogging) {
Mockito.doNothing().when(strictnessSpy).log(Mockito.any(), Mockito.any());
}

i.startRecord("1");
i.literal("data", "foo");
Expand All @@ -418,13 +424,13 @@ private void assertStrictness(final Metafix.Strictness strictness, final String
// TODO: Test logging statements
}

private void assertStrictness(final Metafix.Strictness strictness, final Consumer<Supplier<StreamReceiver>> out) {
assertStrictness(strictness, "upcase('data')", out);
private void assertStrictness(final Metafix.Strictness strictness, final boolean stubLogging, final Consumer<Supplier<StreamReceiver>> out) {
assertStrictness(strictness, "upcase('data')", stubLogging, out);
}

@Test
public void shouldSkipExpressionOnExecutionException() {
assertStrictness(Metafix.Strictness.EXPRESSION, o -> {
assertStrictness(Metafix.Strictness.EXPRESSION, true, o -> {
o.get().startRecord("1");
o.get().literal("before", "");
o.get().literal("data", "FOO");
Expand All @@ -446,7 +452,7 @@ public void shouldSkipExpressionOnExecutionException() {

@Test
public void shouldSkipRecordOnExecutionException() {
assertStrictness(Metafix.Strictness.RECORD, o -> {
assertStrictness(Metafix.Strictness.RECORD, true, o -> {
o.get().startRecord("1");
o.get().literal("before", "");
o.get().literal("data", "FOO");
Expand All @@ -464,15 +470,15 @@ public void shouldSkipRecordOnExecutionException() {
@Test
public void shouldAbortProcessOnExecutionException() {
MetafixTestHelpers.assertExecutionException(IllegalStateException.class, "Expected String, got Array", () ->
assertStrictness(Metafix.Strictness.PROCESS, o -> {
assertStrictness(Metafix.Strictness.PROCESS, false, o -> {
})
);
}

@Test
public void shouldAbortProcessOnProcessException() {
MetafixTestHelpers.assertProcessException(IllegalArgumentException.class, "No enum constant org.metafacture.metafix.FixMethod.foo", () ->
assertStrictness(Metafix.Strictness.EXPRESSION, "foo()", o -> {
assertStrictness(Metafix.Strictness.EXPRESSION, "foo()", false, o -> {
})
);
}
Expand Down

0 comments on commit 6291ed5

Please sign in to comment.