11package edu .wpi .grip .core .serialization ;
22
3- import com .google .common .base .Throwables ;
43import com .google .common .eventbus .EventBus ;
54import com .google .common .eventbus .Subscribe ;
65import com .google .inject .Guice ;
98import com .google .inject .TypeLiteral ;
109import edu .wpi .grip .core .*;
1110import edu .wpi .grip .core .events .OperationAddedEvent ;
12- import edu .wpi .grip .core .operations .Operations ;
1311import edu .wpi .grip .core .sources .ImageFileSource ;
14- import edu .wpi .grip .core .util .MockExceptionWitness ;
15- import edu .wpi .grip .generated .CVOperations ;
16- import org .junit .After ;
12+ import edu .wpi .grip .util .Files ;
1713import org .junit .Before ;
1814import org .junit .Test ;
1915
2016import java .io .*;
21- import java .net .URL ;
22- import java .nio .file .Paths ;
23- import java .util .ArrayList ;
17+ import java .net .URI ;
2418import java .util .List ;
2519import java .util .Optional ;
2620
2721import static junit .framework .TestCase .assertEquals ;
2822
2923public class CompatibilityTest {
3024
25+ private static final URI testphotoURI = Files .testphotoURI ;
26+ private static final URI testprojectURI = Files .testprojectURI ;
27+
3128 private Connection .Factory <Object > connectionFactory ;
3229 private ImageFileSource .Factory imageSourceFactory ;
3330 private Step .Factory stepFactory ;
@@ -61,22 +58,9 @@ public void setUp() throws Exception {
6158 project = injector .getInstance (Project .class );
6259 stepFactory = injector .getInstance (Step .Factory .class );
6360
64- //Set up stuff we need to add the operations
65- this .operationList = new ArrayList <>();
66- this .throwableOptional = Optional .empty ();
67- this .eventBus = new EventBus ((exception , context ) -> throwableOptional = Optional .of (exception ));
68-
69- //Set up the operation grabber to help us register the operations
70- this .eventBus .register (new OperationGrabber ());
71-
7261 //Set up the test project file to work with this machine
73- URL location = CompatibilityTest .class .getProtectionDomain ().getCodeSource ().getLocation ();
74-
75- int numbOfFolders = Paths .get (location .toURI ()).getNameCount ();
76-
77-
78- String fileName = "/" + Paths .get (location .toURI ()).subpath (0 ,(numbOfFolders -4 )).toString ()+ "/testALL.grip" ;
79- String photoFileName = "/" + Paths .get (location .toURI ()).subpath (0 ,(numbOfFolders -4 )).toString ()+ "/testphoto.png" ;
62+ String fileName = testprojectURI .toString ().substring (5 );
63+ String photoFileName = testphotoURI .toString ().substring (5 );
8064
8165 File file = new File (fileName );
8266
@@ -88,39 +72,20 @@ public void setUp() throws Exception {
8872 }
8973 reader .close ();
9074 String newtext = oldtext .replaceAll ("REPLACEME" , photoFileName );
75+
9176 //TODO: replace "preferences" section to work with this machine
9277 FileWriter writer2 = new FileWriter (file );
9378 writer2 .write (newtext );
9479 writer2 .close ();
9580
96- //Add/register/create the operations
97- CVOperations .addOperations (eventBus );
98- for (Operation operation : operationList ) {
99- new Step .Factory (eventBus , (origin ) -> new MockExceptionWitness (eventBus , origin )).create (operation );
100- }
101-
102- Operations .addOperations (eventBus );
103- for (Operation operation : operationList ) {
104- new Step .Factory (eventBus , (origin ) -> new MockExceptionWitness (eventBus , origin )).create (operation );
105- }
106-
10781 //Open the test file as a project
10882 project .open (file );
10983 }
11084
111- @ After
112- public void afterTest () {
113- //Throw any exceptions that weren't handled during the test
114- if (throwableOptional .isPresent ()) {
115- throw Throwables .propagate (throwableOptional .get ());
116- }
117- }
118-
11985 @ Test
12086 public void testFoo () throws Exception {
12187
122- assertEquals ("blarg" ,
123- 3 , 3 );
88+ assertEquals ("blarg" , 3 , 3 );
12489
12590 }
12691}
0 commit comments