X Tutup
Skip to content

Commit dc5fa43

Browse files
committed
getting Junit test to work on installations that have empty spaces in directory names
1 parent 5edfed4 commit dc5fa43

File tree

2 files changed

+47
-26
lines changed

2 files changed

+47
-26
lines changed

biojava-core/src/test/java/org/biojava/nbio/core/search/io/blast/BlastTabularParserTest.java

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
/*
2-
* BioJava development code
3-
*
4-
* This code may be freely distributed and modified under the
5-
* terms of the GNU Lesser General Public Licence. This should
6-
* be distributed with the code. If you do not have a copy,
7-
* see:
8-
*
9-
* http://www.gnu.org/copyleft/lesser.html
10-
*
11-
* Copyright for this code is held jointly by the individual
12-
* authors. These should be listed in @author doc comments.
13-
*
14-
* For more information on the BioJava project and its aims,
15-
* or to join the biojava-l mailing list, visit the home page
16-
* at:
17-
*
18-
* http://www.biojava.org/
19-
*
20-
*/
1+
/*
2+
* BioJava development code
3+
*
4+
* This code may be freely distributed and modified under the
5+
* terms of the GNU Lesser General Public Licence. This should
6+
* be distributed with the code. If you do not have a copy,
7+
* see:
8+
*
9+
* http://www.gnu.org/copyleft/lesser.html
10+
*
11+
* Copyright for this code is held jointly by the individual
12+
* authors. These should be listed in @author doc comments.
13+
*
14+
* For more information on the BioJava project and its aims,
15+
* or to join the biojava-l mailing list, visit the home page
16+
* at:
17+
*
18+
* http://www.biojava.org/
19+
*
20+
*/
2121
package org.biojava.nbio.core.search.io.blast;
2222

2323
import java.io.File;
@@ -86,6 +86,17 @@ public void testSetFile() {
8686
instance.setFile(f);
8787
}
8888

89+
90+
protected File getFileForResource(String resource){
91+
URL resourceURL = this.getClass().getResource(resource);
92+
String filepath = resourceURL.getFile();
93+
filepath = filepath.replaceAll("%20"," ");
94+
95+
File file = new File(filepath);
96+
97+
return file;
98+
}
99+
89100
/**
90101
* Test of createObjects method, of class BlastTabularParser.
91102
*/
@@ -97,8 +108,7 @@ public void testCreateObjects() throws Exception {
97108
Hsp expHsp1hit1res1;
98109

99110
String resource = "/org/biojava/nbio/core/search/io/blast/small-blastreport.blasttxt";
100-
URL resourceURL = getClass().getResource(resource);
101-
File file = new File(resourceURL.getFile());
111+
File file = getFileForResource(resource);
102112

103113
BlastTabularParser instance = new BlastTabularParser();
104114
instance.setFile(file);
@@ -163,8 +173,8 @@ public void testCreateObjects() throws Exception {
163173

164174

165175
String resource2 = "/org/biojava/nbio/core/search/io/blast/testBlastTabularReport.txt";
166-
URL resourceURL2 = getClass().getResource(resource2);
167-
File file2 = new File(resourceURL2.getFile());
176+
177+
File file2 = getFileForResource(resource2);
168178

169179
BlastTabularParser instance2 = new BlastTabularParser();
170180
instance2.setFile(file2);

biojava-core/src/test/java/org/biojava/nbio/core/search/io/blast/BlastXMLParserTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ public void testSetFile() {
7171
instance.setFile(f);
7272
}
7373

74+
protected File getFileForResource(String resource){
75+
URL resourceURL = this.getClass().getResource(resource);
76+
String filepath = resourceURL.getFile();
77+
filepath = filepath.replaceAll("%20"," ");
78+
79+
File file = new File(filepath);
80+
81+
return file;
82+
}
83+
7484
/**
7585
* Test of createObjects method, of class BlastXMLParser.
7686
*/
@@ -79,8 +89,9 @@ public void testCreateObjects() throws Exception {
7989
System.out.println("createObjects");
8090

8191
String resource = "/org/biojava/nbio/core/search/io/blast/small-blastreport.blastxml";
82-
URL resourceURL = getClass().getResource(resource);
83-
File file = new File(resourceURL.getFile());
92+
93+
94+
File file = getFileForResource(resource);
8495

8596
BlastXMLParser instance = new BlastXMLParser();
8697
instance.setFile(file);

0 commit comments

Comments
 (0)
X Tutup