1818import java .io .IOException ;
1919import java .io .InputStream ;
2020import java .io .OutputStream ;
21+ import java .nio .file .Files ;
2122
2223import at .tomtasche .reader .background .CoreWrapper ;
2324
@@ -27,6 +28,12 @@ public class CoreTest {
2728
2829 private File m_testFile ;
2930
31+ @ Before
32+ public void initializeCore () {
33+ Context testCtx = InstrumentationRegistry .getInstrumentation ().getContext ();
34+ CoreWrapper .initialize (testCtx );
35+ }
36+
3037 @ Before
3138 public void extractTestFile () throws IOException {
3239 Context appCtx = InstrumentationRegistry .getInstrumentation ().getTargetContext ();
@@ -47,7 +54,7 @@ public void cleanupTestFile() {
4754 }
4855
4956 private static void copy (InputStream src , File dst ) throws IOException {
50- try (OutputStream out = new FileOutputStream (dst )) {
57+ try (OutputStream out = Files . newOutputStream (dst . toPath () )) {
5158 byte [] buf = new byte [1024 ];
5259 int len ;
5360 while ((len = src .read (buf )) > 0 ) {
@@ -58,8 +65,6 @@ private static void copy(InputStream src, File dst) throws IOException {
5865
5966 @ Test
6067 public void test () {
61- CoreWrapper core = new CoreWrapper ();
62-
6368 File cacheDir = InstrumentationRegistry .getInstrumentation ().getTargetContext ().getCacheDir ();
6469 File htmlFile = new File (cacheDir , "html" );
6570
@@ -68,15 +73,15 @@ public void test() {
6873 coreOptions .outputPath = htmlFile .getPath ();
6974 coreOptions .editable = true ;
7075
71- CoreWrapper .CoreResult coreResult = core .parse (coreOptions );
76+ CoreWrapper .CoreResult coreResult = CoreWrapper .parse (coreOptions );
7277 Assert .assertEquals (0 , coreResult .errorCode );
7378
7479 File resultFile = new File (cacheDir , "result" );
7580 coreOptions .outputPath = resultFile .getPath ();
7681
7782 String htmlDiff = "{\" modifiedText\" :{\" 3\" :\" This is a simple test document to demonstrate the DocumentLoadewwwwr example!\" }}" ;
7883
79- CoreWrapper .CoreResult result = core .backtranslate (coreOptions , htmlDiff );
84+ CoreWrapper .CoreResult result = CoreWrapper .backtranslate (coreOptions , htmlDiff );
8085 Assert .assertEquals (0 , coreResult .errorCode );
8186 }
8287}
0 commit comments