File tree Expand file tree Collapse file tree 4 files changed +14
-5
lines changed Expand file tree Collapse file tree 4 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -94,7 +94,12 @@ android {
9494 }
9595
9696 sourceSets {
97+ // use kotlin only in tests (for now)
9798 test. java. srcDirs + = ' src/test/kotlin'
99+
100+ // use main assets and resources in test
101+ test. assets. srcDirs + = ' src/main/assets'
102+ test. resources. srcDirs + = ' src/main/resoures'
98103 }
99104
100105 buildTypes {
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ public class NearbyPlaces {
3434
3535 public NearbyPlaces () {
3636 try {
37- wikidataQuery = FileUtils .readFromResource ("/assets/ queries/nearby_query.rq" );
37+ wikidataQuery = FileUtils .readFromResource ("/queries/nearby_query.rq" );
3838 Timber .v (wikidataQuery );
3939 } catch (IOException e ) {
4040 throw new RuntimeException (e );
Original file line number Diff line number Diff line change 44
55import java .io .BufferedReader ;
66import java .io .File ;
7+ import java .io .FileNotFoundException ;
78import java .io .FileOutputStream ;
89import java .io .IOException ;
10+ import java .io .InputStream ;
911import java .io .InputStreamReader ;
1012import java .io .OutputStreamWriter ;
1113
@@ -16,16 +18,18 @@ public class FileUtils {
1618 /**
1719 * Read and return the content of a resource file as string.
1820 *
19- * @param fileName asset file's path (e.g. "/assets/ queries/nearby_query.rq")
21+ * @param fileName asset file's path (e.g. "/queries/nearby_query.rq")
2022 * @return the content of the file
2123 */
2224 public static String readFromResource (String fileName ) throws IOException {
2325 StringBuilder buffer = new StringBuilder ();
2426 BufferedReader reader = null ;
2527 try {
26- reader = new BufferedReader (
27- new InputStreamReader (
28- CommonsApplication .class .getResourceAsStream (fileName ), "UTF-8" ));
28+ InputStream inputStream = FileUtils .class .getResourceAsStream (fileName );
29+ if (inputStream == null ) {
30+ throw new FileNotFoundException (fileName );
31+ }
32+ reader = new BufferedReader (new InputStreamReader (inputStream , "UTF-8" ));
2933 String line ;
3034 while ((line = reader .readLine ()) != null ) {
3135 buffer .append (line + "\n " );
File renamed without changes.
You can’t perform that action at this time.
0 commit comments