Skip to content

Commit 4aa4461

Browse files
committed
Move query file from assets to resources
1 parent 9acf22b commit 4aa4461

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

app/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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 {

app/src/main/java/fr/free/nrw/commons/nearby/NearbyPlaces.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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);

app/src/main/java/fr/free/nrw/commons/utils/FileUtils.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
import java.io.BufferedReader;
66
import java.io.File;
7+
import java.io.FileNotFoundException;
78
import java.io.FileOutputStream;
89
import java.io.IOException;
10+
import java.io.InputStream;
911
import java.io.InputStreamReader;
1012
import 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");

0 commit comments

Comments
 (0)