1919
2020package ubic .basecode .ontology .providers ;
2121
22- import java .io .File ;
23- import java .net .URL ;
24- import java .util .Collection ;
25-
2622import org .junit .AfterClass ;
2723import org .junit .BeforeClass ;
28- import org .junit .Ignore ;
2924import org .junit .Test ;
30-
3125import ubic .basecode .ontology .jena .OntologyLoader ;
3226import ubic .basecode .ontology .model .OntologyTerm ;
3327import ubic .basecode .util .Configuration ;
3428
29+ import java .io .File ;
30+ import java .net .URL ;
31+ import java .util .Collection ;
32+
3533import static org .junit .Assert .*;
34+ import static org .junit .Assume .assumeTrue ;
3635
3736/**
3837 * @author mjacobson
3938 */
4039public class AbstractOntologyServiceTest {
4140
4241 private static String prevDir = null ;
43- private static String dataResource = "/data/nif.organism.test.owl.xml" ;
42+ private static final String dataResource = "/data/nif.organism.test.owl.xml" ;
4443
4544 @ BeforeClass
4645 public static void setup () throws Exception {
@@ -54,54 +53,46 @@ public static void tearDown() throws Exception {
5453 }
5554
5655 @ Test
57- @ Ignore ("This test was always broken, but the failure was obscured in a thread." )
5856 public void testCacheOntologyToDisk () throws Exception {
5957 String name = "fooTEST1234" ;
6058
6159 File f = OntologyLoader .getDiskCachePath ( name );
60+ assertNotNull ( f );
6261 if ( f .exists () ) {
63- f . delete ();
62+ assumeTrue ( String . format ( "Failed to delete existing ontology cache file %s." , f . getAbsolutePath () ), f . delete () );
6463 }
6564
66- assertTrue ( ! f .exists () );
65+ assertFalse ( f .exists () );
6766
6867 URL resource = this .getClass ().getResource ( dataResource );
68+ assertNotNull ( resource );
6969 GenericOntologyService s = createService ( name , resource .toString (), true );
7070
7171 Collection <OntologyTerm > r = s .findTerm ( "Mouse" );
72- assertTrue ( ! r .isEmpty () );
72+ assertFalse ( r .isEmpty () );
7373
7474 // Check if cache was created
7575 assertTrue ( f .exists () );
76- assertTrue ( f .length () != 0 );
76+ assertNotEquals ( 0 , f .length () );
7777
7878 // Recreate OntologyService using this cache file
7979 s = createService ( name , "/data/NONEXISTENT_RESOURCE" , true );
8080
8181 r = s .findTerm ( "Mouse" );
82- assertTrue ( ! r .isEmpty () );
82+ assertFalse ( r .isEmpty () );
8383
8484 // Recreate OntologyService with bad URL and no cache
85- s = createService ( "NO_CACHE_WITH_THIS_NAME" , "/data/NONEXISTENT_RESOURCE" , true );
86-
87- r = s .findTerm ( "Mouse" );
88- assertTrue ( r .isEmpty () );
89-
85+ assertThrows ( RuntimeException .class , () -> createService ( "NO_CACHE_WITH_THIS_NAME" , "/data/NONEXISTENT_RESOURCE" , true ) );
9086 }
9187
9288 @ Test
9389 public void testGenericOntologyServiceMem () throws Exception {
9490 URL resource = this .getClass ().getResource ( dataResource );
95-
91+ assertNotNull ( resource );
9692 GenericOntologyService s = createService ( "foo" , resource .toString (), false );
9793
9894 Collection <OntologyTerm > r = s .findTerm ( "Mouse" );
99- assertTrue ( !r .isEmpty () );
100-
101- }
102-
103- @ Test
104- public void testReindexOnInitialize () throws Exception {
95+ assertFalse ( r .isEmpty () );
10596
10697 }
10798
@@ -118,7 +109,7 @@ public void testInitializeInBackgroundThread() throws InterruptedException {
118109 assertFalse ( s .isInitializationThreadAlive () );
119110 }
120111
121- private GenericOntologyService createService ( String name , String resourceURL , boolean cache ) throws Exception {
112+ private GenericOntologyService createService ( String name , String resourceURL , boolean cache ) {
122113 GenericOntologyService s = new GenericOntologyService ( name , resourceURL , cache );
123114 s .initialize ( true , false );
124115 return s ;
0 commit comments