ソースを参照

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年前
コミット
164680c001
1個のファイルの変更11行の追加3行の削除
  1. 11
    3
      test/com/dmdirc/logger/ErrorReporterTest.java

+ 11
- 3
test/com/dmdirc/logger/ErrorReporterTest.java ファイルの表示

@@ -25,6 +25,7 @@ package com.dmdirc.logger;
25 25
 import java.util.Date;
26 26
 
27 27
 import org.junit.Before;
28
+import org.junit.BeforeClass;
28 29
 import org.junit.Test;
29 30
 import org.junit.runner.RunWith;
30 31
 import org.mockito.ArgumentCaptor;
@@ -43,20 +44,27 @@ import net.kencochrane.raven.event.interfaces.SentryInterface;
43 44
 import static org.junit.Assert.assertEquals;
44 45
 import static org.junit.Assert.assertNotNull;
45 46
 import static org.junit.Assert.assertTrue;
47
+import static org.mockito.Mockito.mock;
46 48
 import static org.mockito.Mockito.verify;
47 49
 import static org.mockito.Mockito.when;
48 50
 
49 51
 @RunWith(MockitoJUnitRunner.class)
50 52
 public class ErrorReporterTest {
51 53
 
52
-    @Mock private RavenFactory ravenFactory;
54
+    private static RavenFactory ravenFactory;
53 55
     @Mock private Raven raven;
54 56
     @Captor private ArgumentCaptor<Event> eventCaptor;
55 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 63
         RavenFactory.registerFactory(ravenFactory);
64
+    }
65
+
66
+    @Before
67
+    public void setUp() {
60 68
         when(ravenFactory.createRavenInstance(Matchers.<Dsn>anyObject())).thenReturn(raven);
61 69
         errorReporter = new ErrorReporter();
62 70
     }

読み込み中…
キャンセル
保存