X Tutup
Skip to content

Commit e1dbb04

Browse files
committed
#610 switching test to junit version 4
1 parent 1ce3e1e commit e1dbb04

File tree

1 file changed

+54
-15
lines changed

1 file changed

+54
-15
lines changed

biojava-modfinder/src/test/java/org/biojava/nbio/protmod/phosphosite/TestAcetylation.java

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,80 @@
11
package org.biojava.nbio.protmod.phosphosite;
22

3-
import junit.framework.TestCase;
3+
44
import org.biojava.nbio.phosphosite.Dataset;
55
import org.biojava.nbio.phosphosite.Site;
6+
import org.junit.Before;
7+
import org.junit.Test;
68

79
import java.io.File;
10+
import java.io.IOException;
811
import java.net.URL;
912
import java.util.List;
1013

11-
/**
14+
import static org.junit.Assert.assertTrue;
15+
import static org.junit.Assert.fail;
16+
17+
/** Makes sure there is a local installation of the Acetyaltion site file from Phosphosite and
18+
* tests if it can get parsed by the parser.
19+
*
1220
* Created by andreas on 11/29/16.
1321
*/
14-
public class TestAcetylation extends TestCase {
22+
public class TestAcetylation {
1523

1624

17-
/** Tests that the acetylation file can get downloaded and parsed
25+
/** Make sure an Acetylation file is available locally.
26+
* Downloads from Phosphosite if needed.
1827
*
1928
*/
20-
public void testAcetylation() {
21-
String f = Dataset.ACETYLATION;
29+
@Before
30+
public void setUp(){
2231

2332
Dataset ds = new Dataset();
2433

25-
try {
26-
File localDir = ds.getLocalDir();
27-
if ( ! localDir.exists())
28-
localDir.mkdir();
29-
30-
int slashIndex = f.lastIndexOf("/");
31-
32-
String fileName = f.substring(slashIndex);
34+
String f = Dataset.ACETYLATION;
3335

34-
File localFile = new File(localDir + "/" + fileName);
36+
File localFile = getLocalFileName(f);
3537

38+
try {
3639
if (!localFile.exists()) {
3740
ds.downloadFile(new URL(f), localFile);
3841
}
42+
} catch (IOException e) {
43+
e.printStackTrace();
44+
}
45+
}
46+
47+
/** returns the local file name where the Acetylation file will get cached locally.
48+
*
49+
* @param phosphoSiteFileLocation location of file at PhosphoSitePlus.
50+
* @return a File pointing to the location of the locally cached file.
51+
*/
52+
private File getLocalFileName(String phosphoSiteFileLocation){
53+
54+
Dataset ds = new Dataset();
55+
File localDir = ds.getLocalDir();
56+
if ( ! localDir.exists()) {
57+
boolean success = localDir.mkdir();
58+
if ( ! success)
59+
fail("Could not create directory " + localDir.getAbsolutePath());
60+
}
61+
62+
int slashIndex = phosphoSiteFileLocation.lastIndexOf("/");
63+
64+
String fileName = phosphoSiteFileLocation.substring(slashIndex);
65+
66+
return new File(localDir + "/" + fileName);
67+
}
68+
69+
/** Tests that the acetylation file can get parsed without problems.
70+
*
71+
*/
72+
@Test
73+
public void testAcetylation() {
74+
75+
try {
76+
77+
File localFile = getLocalFileName(Dataset.ACETYLATION);
3978

4079
List<Site> sites = Site.parseSites(localFile);
4180

0 commit comments

Comments
 (0)
X Tutup