Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce @MetafixToDo annotation to mark tests as disabled. #158

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ subprojects {
'equalsverifier': '3.8.2',
'jetty': '9.4.14.v20181114',
'jquery': '3.3.1-1',
'junit_jupiter': '5.4.2',
'junit_jupiter': '5.8.2',
'junit_platform': '1.4.2',
'metafacture': '5.3.1',
'mockito': '2.27.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.metafacture.framework.StreamReceiver;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
Expand All @@ -32,6 +31,7 @@
* @author Fabian Steeg
*/
@ExtendWith(MockitoExtension.class)
@ExtendWith(MetafixToDo.Extension.class)
public class MetafixBindTest {

@Mock
Expand Down Expand Up @@ -442,7 +442,7 @@ public void doListIndexedArrayOfObjectsToArrayOfObjects() {
}

@Test
@Disabled("implement Fix-style binds with collectors?")
@MetafixToDo("implement Fix-style binds with collectors?")
public void ifInCollector() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do entity('author')",
Expand All @@ -466,7 +466,7 @@ public void ifInCollector() {
}

@Test
@Disabled("implement Fix-style binds with collectors?")
@MetafixToDo("implement Fix-style binds with collectors?")
public void ifInCollectorMultiRecords() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do entity('author')",
Expand Down Expand Up @@ -510,7 +510,7 @@ public void ifInCollectorMultiRecords() {
}

@Test
@Disabled("implement Fix-style binds with collectors?")
@MetafixToDo("implement Fix-style binds with collectors?")
public void ifInCollectorChoose() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do choose(flushWith: 'record')",
Expand All @@ -537,7 +537,7 @@ public void ifInCollectorChoose() {
}

@Test
@Disabled("implement Fix-style binds with collectors?")
@MetafixToDo("implement Fix-style binds with collectors?")
public void ifInCollectorCombine() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"do combine(name: 'fullName', value: '${first} ${last}')",
Expand Down Expand Up @@ -656,7 +656,7 @@ public void shouldIterateOverListOfHashesWithCharacterClass() {

@Test
// See https://github.com/metafacture/metafacture-fix/issues/119
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/143")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/143")
public void shouldIterateOverListOfHashesWithAlternation() {
shouldIterateOverListOfHashes("name.value|nome.value", 3);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.metafacture.framework.StreamReceiver;

import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
Expand All @@ -34,6 +33,7 @@
* @author Fabian Steeg
*/
@ExtendWith(MockitoExtension.class)
@ExtendWith(MetafixToDo.Extension.class)
public class MetafixMethodTest {

@Mock
Expand Down Expand Up @@ -1306,7 +1306,7 @@ public void shouldReplaceAllRegexesInArrayByIndex() {
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/135")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/135")
public void shouldReplaceAllRegexesInArrayByArrayWildcard() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"replace_all('names.$last', 'a', 'X')"
Expand Down Expand Up @@ -1358,7 +1358,7 @@ public void shouldReplaceAllRegexesInArraySubFieldByIndex() {
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/135")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/135")
public void shouldReplaceAllRegexesInArraySubFieldByArrayWildcard() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"replace_all('names[].$last.name', 'a', 'X')"
Expand Down Expand Up @@ -1428,7 +1428,7 @@ public void shouldReverseArray() {
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/121")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldReverseArrayOfStringsWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"reverse('test[].*')"
Expand All @@ -1455,7 +1455,7 @@ public void shouldReverseArrayOfStringsWithAsterisk() {
}

@Test
@Disabled("java.lang.ArrayIndexOutOfBoundsException: 0; see https://github.com/metafacture/metafacture-fix/issues/121")
@MetafixToDo("java.lang.ArrayIndexOutOfBoundsException: 0; see https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldReverseArrayOfHashesWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"reverse('ANIMALS[].*')"
Expand Down Expand Up @@ -1626,7 +1626,7 @@ public void shouldSortFieldAndRemoveDuplicates() {
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/121")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldSortArrayFieldWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"sort_field('OTHERS[].*.dnimals[]')"
Expand Down Expand Up @@ -1717,7 +1717,7 @@ public void shouldSplitArrayField() {
}

@Test
@Disabled("Arrays in arrays need to be preserved. See disabled isArray in FixPath#appendIn.")
@MetafixToDo("Arrays in arrays need to be preserved. See disabled isArray in FixPath#appendIn.")
public void moveToNestedArray() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"move_field('date[]', 'd[]')"
Expand Down Expand Up @@ -1757,7 +1757,7 @@ public void moveToNestedArray() {
}

@Test
@Disabled("Arrays in arrays need to be preserved. See disabled isArray in FixPath#appendIn.")
@MetafixToDo("Arrays in arrays need to be preserved. See disabled isArray in FixPath#appendIn.")
public void shouldSplitMarkedArrayFieldIntoArrayOfArrays() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"split_field('date[]', '-')"
Expand Down Expand Up @@ -1815,7 +1815,7 @@ public void shouldSplitHashField() {
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/100 and https://github.com/metafacture/metafacture-fix/issues/121")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/100 and https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldSplitNestedField() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"split_field('others[].*.tools', '--')"
Expand Down Expand Up @@ -1864,7 +1864,7 @@ public void shouldSumNumbers() {
}

@Test
@Disabled("java.lang.IllegalStateException: Expected String, got Array; see https://github.com/metafacture/metafacture-fix/issues/121")
@MetafixToDo("java.lang.IllegalStateException: Expected String, got Array; see https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldSumArrayFieldWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"sum('OTHERS[].*.dumbers[]')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.metafacture.framework.StreamReceiver;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentMatchers;
Expand All @@ -34,6 +33,7 @@
* @author Fabian Steeg
*/
@ExtendWith(MockitoExtension.class) // checkstyle-disable-line JavaNCSS
@ExtendWith(MetafixToDo.Extension.class)
public class MetafixRecordTest {

@Mock
Expand Down Expand Up @@ -426,7 +426,7 @@ public void complexAppendWithArrayOfStrings() {
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/92")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/92")
public void complexAppendWithArrayOfObjects() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"copy_field('others', 'animals[].$append')",
Expand Down Expand Up @@ -741,7 +741,7 @@ public void shouldCopyArrayFieldWithAsterisk() {
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/121")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldCopyNestedArrayFieldWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"set_array('TEST_4[]')",
Expand Down Expand Up @@ -1098,7 +1098,7 @@ private void assertThrowsOnEmptyRecord(final String index) {
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/121")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldAddArraySubFieldWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"add_field('coll[].*.c', 'test')"
Expand Down Expand Up @@ -2409,7 +2409,7 @@ public void shouldAddRandomNumberToUnmarkedArray() {
}

@Test
@Disabled("See https://github.com/metafacture/metafacture-fix/issues/100")
@MetafixToDo("See https://github.com/metafacture/metafacture-fix/issues/100")
public void shouldNotAppendRandomNumberToHash() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"random('animals.$append', '100')"
Expand Down Expand Up @@ -2518,7 +2518,7 @@ public void shouldRecursivelyRenameFieldsInArray() {
}

@Test
@Disabled("java.lang.ArrayIndexOutOfBoundsException: 0; see https://github.com/metafacture/metafacture-fix/issues/100")
@MetafixToDo("java.lang.ArrayIndexOutOfBoundsException: 0; see https://github.com/metafacture/metafacture-fix/issues/100")
public void shouldRenameAllFieldsInHash() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"rename('.', ani, XY)"
Expand Down Expand Up @@ -2562,7 +2562,7 @@ public void shouldRenameAllFieldsInHash() {
}

@Test
@Disabled("java.lang.ArrayIndexOutOfBoundsException: 0; see https://github.com/metafacture/metafacture-fix/issues/121")
@MetafixToDo("java.lang.ArrayIndexOutOfBoundsException: 0; see https://github.com/metafacture/metafacture-fix/issues/121")
public void shouldRenameArrayFieldWithAsterisk() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"rename('OTHERS[].*', 'd', 'XY')"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.metafacture.framework.StreamReceiver;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
Expand All @@ -33,7 +32,7 @@
*
*/
@ExtendWith(MockitoExtension.class)
@Disabled("TODO: support Fix-style selectors https://github.com/LibreCat/Catmandu/wiki/Selectors")
@ExtendWith(MetafixToDo.Extension.class)
public final class MetafixSelectorTest {

@Mock
Expand All @@ -42,6 +41,7 @@ public final class MetafixSelectorTest {
public MetafixSelectorTest() { }

@Test
@MetafixToDo("Support reject() with condition")
public void reject() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"reject exists(error)"),
Expand All @@ -64,19 +64,23 @@ public void rejectWithExplicitConditional() {
MetafixTestHelpers.assertFix(streamReceiver, Arrays.asList(
"if exists(error)",
" reject()",
"end"),
"end"
),
i -> {
i.startRecord("1");
i.literal("error", "details");
i.endRecord();

i.startRecord("2");
i.literal("name", "Mary");
i.endRecord();
}, o -> {
},
o -> {
o.get().startRecord("2");
o.get().literal("name", "Mary");
o.get().endRecord();
});
}
);
}

}
81 changes: 81 additions & 0 deletions metafix/src/test/java/org/metafacture/metafix/MetafixToDo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.metafacture.metafix;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.InvocationInterceptor;
import org.junit.jupiter.api.extension.ReflectiveInvocationContext;
import org.opentest4j.TestAbortedException;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.function.Consumer;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(MetafixToDo.Handler.class)
public @interface MetafixToDo {

String value();

class Extension implements InvocationInterceptor {

private Extension() {
}

@Override
public void interceptTestMethod(final InvocationInterceptor.Invocation<Void> invocation, final ReflectiveInvocationContext<Method> invocationContext, final ExtensionContext extensionContext) throws Throwable {
try {
invocation.proceed();
}
catch (final Throwable e) { // checkstyle-disable-line IllegalCatch
handleAnnotation(invocationContext, a -> {
throw new TestAbortedException(a.value(), e);
});

throw e;
}

handleAnnotation(invocationContext, a -> Assertions.fail("Marked as " + a + ", but passed."));
}

private void handleAnnotation(final ReflectiveInvocationContext<Method> invocationContext, final Consumer<MetafixToDo> consumer) {
final MetafixToDo annotation = invocationContext.getExecutable().getAnnotation(MetafixToDo.class);

if (annotation != null) {
consumer.accept(annotation);
}
}

}

class Handler implements ExecutionCondition {

private static final Class<Extension> EXTENSION_CLASS = Extension.class;
private static final String EXTENSION_NAME = EXTENSION_CLASS.getTypeName();

private Handler() {
}

@Override
public ConditionEvaluationResult evaluateExecutionCondition(final ExtensionContext context) {
for (final ExtendWith annotation : context.getTestClass().get().getAnnotationsByType(ExtendWith.class)) {
for (final Class<? extends org.junit.jupiter.api.extension.Extension> extensionClass : annotation.value()) {
if (extensionClass.isAssignableFrom(EXTENSION_CLASS)) {
return ConditionEvaluationResult.enabled("Extension present: " + EXTENSION_NAME);
}
}
}

Assertions.fail("Extension missing: " + EXTENSION_NAME);
return null; // not reached
}

}

}