1+
12package org .scijava .ops .engine ;
23
34import static org .junit .Assert .assertEquals ;
67
78import java .util .ArrayList ;
89import java .util .Arrays ;
10+ import java .util .Collections ;
911import java .util .Iterator ;
1012import java .util .List ;
1113import java .util .ServiceLoader ;
1214
1315import org .junit .AfterClass ;
1416import org .junit .BeforeClass ;
15- import org .scijava .Context ;
16- import org .scijava .cache .CacheService ;
1717import org .scijava .discovery .Discoverer ;
1818import org .scijava .discovery .StaticDiscoverer ;
1919import org .scijava .log2 .Logger ;
2020import org .scijava .log2 .StderrLogFactory ;
2121import org .scijava .ops .api .OpEnvironment ;
22+ import org .scijava .ops .api .OpHistory ;
2223import org .scijava .ops .api .OpInfoGenerator ;
2324import org .scijava .ops .api .features .MatchingRoutine ;
2425import org .scijava .ops .engine .impl .DefaultOpEnvironment ;
2728import org .scijava .ops .engine .impl .OpCollectionInfoGenerator ;
2829import org .scijava .ops .engine .impl .PluginBasedClassOpInfoGenerator ;
2930import org .scijava .ops .engine .impl .TagBasedOpInfoGenerator ;
31+ import org .scijava .ops .engine .matcher .impl .AdaptationMatchingRoutine ;
3032import org .scijava .ops .engine .matcher .impl .OpWrappers ;
3133import org .scijava .ops .engine .matcher .impl .RuntimeSafeMatchingRoutine ;
32- import org .scijava .parse2 .Parser ;
33- import org .scijava .plugin .PluginService ;
34- import org .scijava .thread .ThreadService ;
34+ import org .scijava .ops .engine .matcher .impl .SimplificationMatchingRoutine ;
3535import org .scijava .types .DefaultTypeReifier ;
3636import org .scijava .types .TypeReifier ;
3737
3838public abstract class AbstractTestEnvironment {
3939
40- protected static Context context ;
41- protected static OpService ops ;
42- protected static PluginService plugins ;
43- protected static Logger log ;
40+ protected static List <Class <? extends MatchingRoutine >> routines () {
41+ return Arrays .asList ( //
42+ RuntimeSafeMatchingRoutine .class , //
43+ AdaptationMatchingRoutine .class , //
44+ SimplificationMatchingRoutine .class //
45+ );
46+ }
47+
48+ protected static List <Class <?>> opContainingClasses () {
49+ return Collections .emptyList ();
50+ }
51+
52+ protected static OpEnvironment ops ;
53+ protected static OpHistory history ;
54+ protected static Logger logger ;
55+ protected static TypeReifier types ;
56+ protected static StaticDiscoverer discoverer ;
4457
4558 @ BeforeClass
4659 public static void setUp () {
47- context = new Context ( OpService . class , CacheService . class , ThreadService . class , Parser . class , PluginService . class );
48- ops = context . getService ( OpService . class );
49- plugins = context . getService ( PluginService . class );
50- log = new StderrLogFactory (). create ( );
60+ logger = new StderrLogFactory (). create ( );
61+ types = new DefaultTypeReifier ( logger , Discoverer . using (
62+ ServiceLoader :: load ) );
63+ ops = barebonesEnvironment ( routines (), opContainingClasses () );
5164 }
5265
5366 @ AfterClass
5467 public static void tearDown () {
55- context .dispose ();
56- context = null ;
57- plugins = null ;
58- log = null ;
59- }
60-
61- protected static OpEnvironment barebonesEnvironment (Class <?>... opClasses ) {
62- List <Class <? extends MatchingRoutine >> routines = Arrays .asList (RuntimeSafeMatchingRoutine .class );
63- return barebonesEnvironment (routines , opClasses );
68+ ops = null ;
69+ logger = null ;
6470 }
6571
66- protected static OpEnvironment barebonesEnvironment (List <Class <? extends MatchingRoutine >> routines , Class <?>... opClasses ) {
67- return barebonesEnvironment (routines , Arrays .asList (opClasses ));
68- }
69-
70- protected static OpEnvironment barebonesEnvironment (List <Class <? extends MatchingRoutine >> routines , List <Class <?>> opClasses ) {
71- TypeReifier t = new DefaultTypeReifier (log , Discoverer .using (ServiceLoader ::load ));
72- StaticDiscoverer d = new StaticDiscoverer ();
73- d .registerAll (routines , "matchingroutine" );
74- d .registerAll (OpWrappers .class .getDeclaredClasses (), "opwrapper" );
75- d .registerAll (opClasses , "" );
72+ protected static OpEnvironment barebonesEnvironment (
73+ List <Class <? extends MatchingRoutine >> routines , List <Class <?>> opClasses )
74+ {
75+ // register needed classes in StaticDiscoverer
76+ discoverer = new StaticDiscoverer ();
77+ discoverer .registerAll (routines , "matchingroutine" );
78+ discoverer .registerAll (OpWrappers .class .getDeclaredClasses (), "opwrapper" );
79+ discoverer .registerAll (opClasses , "" );
80+ // register possibly useful OpInfoGenerators
7681 List <OpInfoGenerator > generators = new ArrayList <>();
77- generators .add ( new OpCollectionInfoGenerator (log , d ));
78- generators .add ( new OpClassBasedClassOpInfoGenerator (log , d ));
79- generators .add ( new PluginBasedClassOpInfoGenerator (log , d ));
80- generators .add ( new TagBasedOpInfoGenerator (log , d ));
81-
82- return new DefaultOpEnvironment (t , log , new DefaultOpHistory (), generators , d );
83- }
82+ generators .add (new OpCollectionInfoGenerator (logger , discoverer ));
83+ generators .add (new OpClassBasedClassOpInfoGenerator (logger , discoverer ));
84+ generators .add (new PluginBasedClassOpInfoGenerator (logger , discoverer ));
85+ generators .add (new TagBasedOpInfoGenerator (logger , discoverer ));
8486
85- protected static OpEnvironment fullEnvironment () {
86- return context .getService (OpService .class ).env ();
87+ history = new DefaultOpHistory ();
88+ // return Op Environment
89+ return new DefaultOpEnvironment (types , logger , history ,
90+ generators , discoverer );
8791 }
88-
92+
8993 protected static boolean arrayEquals (double [] arr1 , Double ... arr2 ) {
9094 return Arrays .deepEquals (Arrays .stream (arr1 ).boxed ().toArray (Double []::new ), arr2 );
9195 }
@@ -101,4 +105,5 @@ protected static <T> void assertIterationsEqual(final Iterable<T> expected,
101105 }
102106 assertFalse ("More elements than expected" , a .hasNext ());
103107 }
108+
104109}
0 commit comments