Selaa lähdekoodia

Fix failures caused by static factory.

Can't register it separately for each test, as it'll just end up
using the first one. And the API doesn't let you remove factories :(
pull/82/head
Chris Smith 9 vuotta sitten
vanhempi
commit
164680c001
1 muutettua tiedostoa jossa 11 lisäystä ja 3 poistoa
  1. 11
    3
      test/com/dmdirc/logger/ErrorReporterTest.java

+ 11
- 3
test/com/dmdirc/logger/ErrorReporterTest.java Näytä tiedosto

25
 import java.util.Date;
25
 import java.util.Date;
26
 
26
 
27
 import org.junit.Before;
27
 import org.junit.Before;
28
+import org.junit.BeforeClass;
28
 import org.junit.Test;
29
 import org.junit.Test;
29
 import org.junit.runner.RunWith;
30
 import org.junit.runner.RunWith;
30
 import org.mockito.ArgumentCaptor;
31
 import org.mockito.ArgumentCaptor;
43
 import static org.junit.Assert.assertEquals;
44
 import static org.junit.Assert.assertEquals;
44
 import static org.junit.Assert.assertNotNull;
45
 import static org.junit.Assert.assertNotNull;
45
 import static org.junit.Assert.assertTrue;
46
 import static org.junit.Assert.assertTrue;
47
+import static org.mockito.Mockito.mock;
46
 import static org.mockito.Mockito.verify;
48
 import static org.mockito.Mockito.verify;
47
 import static org.mockito.Mockito.when;
49
 import static org.mockito.Mockito.when;
48
 
50
 
49
 @RunWith(MockitoJUnitRunner.class)
51
 @RunWith(MockitoJUnitRunner.class)
50
 public class ErrorReporterTest {
52
 public class ErrorReporterTest {
51
 
53
 
52
-    @Mock private RavenFactory ravenFactory;
54
+    private static RavenFactory ravenFactory;
53
     @Mock private Raven raven;
55
     @Mock private Raven raven;
54
     @Captor private ArgumentCaptor<Event> eventCaptor;
56
     @Captor private ArgumentCaptor<Event> eventCaptor;
55
     private ErrorReporter errorReporter;
57
     private ErrorReporter errorReporter;
56
 
58
 
57
-    @Before
58
-    public void setUp() throws Exception {
59
+    @BeforeClass
60
+    public static void setUpClass() {
61
+        // Static calls are horrible.
62
+        ravenFactory = mock(RavenFactory.class);
59
         RavenFactory.registerFactory(ravenFactory);
63
         RavenFactory.registerFactory(ravenFactory);
64
+    }
65
+
66
+    @Before
67
+    public void setUp() {
60
         when(ravenFactory.createRavenInstance(Matchers.<Dsn>anyObject())).thenReturn(raven);
68
         when(ravenFactory.createRavenInstance(Matchers.<Dsn>anyObject())).thenReturn(raven);
61
         errorReporter = new ErrorReporter();
69
         errorReporter = new ErrorReporter();
62
     }
70
     }

Loading…
Peruuta
Tallenna