11package com .bugsnag ;
22
3- import static org .junit .Assert .assertEquals ;
4- import static org .junit .Assert .assertFalse ;
53import static org .junit .Assert .assertNotNull ;
64import static org .junit .Assert .assertTrue ;
75import static org .junit .Assert .fail ;
86
9- import com .fasterxml .jackson .core .JsonProcessingException ;
10- import com .fasterxml .jackson .databind .JsonNode ;
11- import com .fasterxml .jackson .databind .ObjectMapper ;
127import org .junit .Before ;
138import org .junit .Test ;
149
15- import java .io .IOException ;
1610import java .lang .Exception ;
1711import java .util .List ;
1812
@@ -31,15 +25,16 @@ public void setUp() throws Exception {
3125 }
3226
3327 @ Test
34- public void testThreadStateContainsCurrentThread () {
35- int count = 0 ;
28+ public void testThreadStateDoesNotContainCurrentThread () {
3629
3730 for (ThreadState thread : threadStates ) {
3831 if (thread .getId () == Thread .currentThread ().getId ()) {
39- count ++ ;
32+ fail () ;
4033 }
4134 }
42- assertEquals (1 , count );
35+
36+ // Just test that there is at least one thread
37+ assertTrue (threadStates .size () > 1 );
4338 }
4439
4540 @ Test
@@ -56,46 +51,4 @@ public void testThreadStacktrace() {
5651 assertNotNull (stacktrace );
5752 }
5853 }
59-
60- /**
61- * Verifies that the required values for 'thread' are serialised as an array
62- */
63- @ Test
64- public void testSerialisation () throws Exception {
65- JsonNode root = serialiseThreadStateToJson ();
66-
67- for (JsonNode jsonNode : root ) {
68- assertNotNull (jsonNode .get ("id" ).asText ());
69- assertNotNull (jsonNode .get ("name" ).asText ());
70- assertNotNull (jsonNode .get ("stacktrace" ));
71- }
72- }
73-
74- /**
75- * Verifies that the current thread is serialised as an object, and that only this value
76- * contains the errorReportingThread boolean flag
77- */
78- @ Test
79- public void testCurrentThread () throws Exception {
80- JsonNode root = serialiseThreadStateToJson ();
81- long currentThreadId = Thread .currentThread ().getId ();
82- int currentThreadCount = 0 ;
83-
84- for (JsonNode jsonNode : root ) {
85- if (currentThreadId == jsonNode .get ("id" ).asLong ()) {
86- assertTrue (jsonNode .get ("errorReportingThread" ).asBoolean ());
87- currentThreadCount ++;
88- } else {
89- assertFalse (jsonNode .has ("errorReportingThread" ));
90- }
91- }
92- assertEquals (1 , currentThreadCount );
93- }
94-
95- private JsonNode serialiseThreadStateToJson () throws IOException {
96- ObjectMapper mapper = new ObjectMapper ();
97- String json = mapper .writeValueAsString (threadStates );
98- return mapper .readTree (json );
99- }
100-
10154}
0 commit comments