|
| 1 | +package org.scijava.ops.engine; |
| 2 | + |
| 3 | +import java.util.Collection; |
| 4 | +import java.util.Map; |
| 5 | +import java.util.function.Function; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Assertions; |
| 8 | +import org.junit.jupiter.api.BeforeAll; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.scijava.ops.api.InfoTree; |
| 11 | +import org.scijava.ops.api.OpInfo; |
| 12 | +import org.scijava.ops.engine.matcher.impl.OpFieldInfo; |
| 13 | +import org.scijava.ops.spi.OpCollection; |
| 14 | +import org.scijava.ops.spi.OpField; |
| 15 | +import org.scijava.priority.Priority; |
| 16 | + |
| 17 | +public class InfoTreeGeneratorTest extends AbstractTestEnvironment implements |
| 18 | + OpCollection |
| 19 | +{ |
| 20 | + |
| 21 | + @OpField(names="test.infoTreeGeneration") |
| 22 | + public final Function<Double, Double> foo = in -> in + 1; |
| 23 | + |
| 24 | + @BeforeAll |
| 25 | + public static void addNeededOps() { |
| 26 | + ops.register(new DummyInfoTreeGenerator(), new InfoTreeGeneratorTest()); |
| 27 | + } |
| 28 | + |
| 29 | + |
| 30 | + @Test |
| 31 | + public void testMultipleValidInfoTreeGenerators() { |
| 32 | + // Obtain a signature that can be reified by the DefaultInfoTreeGenerator and by our dummy generator |
| 33 | + var op = ops.unary("test.infoTreeGeneration").inType(Double.class).outType(Double.class).function(); |
| 34 | + String signature = ops.history().signatureOf(op); |
| 35 | + // Run treeFromID to make sure our generator doesn't run |
| 36 | + var infoTree = ops.treeFromID(signature); |
| 37 | + // Assert non-null output |
| 38 | + Assertions.assertNotNull(infoTree); |
| 39 | + } |
| 40 | + |
| 41 | + |
| 42 | + static class DummyInfoTreeGenerator implements InfoTreeGenerator { |
| 43 | + |
| 44 | + @Override |
| 45 | + public InfoTree generate(String signature, Map<String, OpInfo> idMap, |
| 46 | + Collection<InfoTreeGenerator> generators) |
| 47 | + { |
| 48 | + return null; |
| 49 | + } |
| 50 | + |
| 51 | + @Override public boolean canGenerate(String signature) { |
| 52 | + return true; |
| 53 | + } |
| 54 | + |
| 55 | + @Override public double getPriority() { |
| 56 | + return Priority.LOW; |
| 57 | + } |
| 58 | + |
| 59 | + } |
| 60 | +} |
0 commit comments