1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -44,28 +44,28 @@ public void nestedRuntimeExceptionWithNoRootCause() {
44
44
nex .printStackTrace (pw );
45
45
pw .flush ();
46
46
String stackTrace = new String (baos .toByteArray ());
47
- assertFalse (stackTrace .indexOf (mesg ) == - 1 );
47
+ assertTrue (stackTrace .contains (mesg ));
48
48
}
49
49
50
50
@ Test
51
51
public void nestedRuntimeExceptionWithRootCause () {
52
52
String myMessage = "mesg for this exception" ;
53
- String rootCauseMesg = "this is the obscure message of the root cause" ;
54
- Exception rootCause = new Exception (rootCauseMesg );
53
+ String rootCauseMsg = "this is the obscure message of the root cause" ;
54
+ Exception rootCause = new Exception (rootCauseMsg );
55
55
// Making a class abstract doesn't _really_ prevent instantiation :-)
56
56
NestedRuntimeException nex = new NestedRuntimeException (myMessage , rootCause ) {};
57
57
assertEquals (nex .getCause (), rootCause );
58
- assertTrue (nex .getMessage ().indexOf (myMessage ) != - 1 );
59
- assertTrue (nex .getMessage ().indexOf ( rootCauseMesg ) != - 1 );
58
+ assertTrue (nex .getMessage ().contains (myMessage ));
59
+ assertTrue (nex .getMessage ().endsWith ( rootCauseMsg ) );
60
60
61
61
// check PrintStackTrace
62
62
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
63
63
PrintWriter pw = new PrintWriter (baos );
64
64
nex .printStackTrace (pw );
65
65
pw .flush ();
66
66
String stackTrace = new String (baos .toByteArray ());
67
- assertFalse (stackTrace .indexOf (rootCause .getClass ().getName ()) == - 1 );
68
- assertFalse (stackTrace .indexOf ( rootCauseMesg ) == - 1 );
67
+ assertTrue (stackTrace .contains (rootCause .getClass ().getName ()));
68
+ assertTrue (stackTrace .contains ( rootCauseMsg ) );
69
69
}
70
70
71
71
@ Test
@@ -82,28 +82,28 @@ public void nestedCheckedExceptionWithNoRootCause() {
82
82
nex .printStackTrace (pw );
83
83
pw .flush ();
84
84
String stackTrace = new String (baos .toByteArray ());
85
- assertFalse (stackTrace .indexOf (mesg ) == - 1 );
85
+ assertTrue (stackTrace .contains (mesg ));
86
86
}
87
87
88
88
@ Test
89
89
public void nestedCheckedExceptionWithRootCause () {
90
90
String myMessage = "mesg for this exception" ;
91
- String rootCauseMesg = "this is the obscure message of the root cause" ;
92
- Exception rootCause = new Exception (rootCauseMesg );
91
+ String rootCauseMsg = "this is the obscure message of the root cause" ;
92
+ Exception rootCause = new Exception (rootCauseMsg );
93
93
// Making a class abstract doesn't _really_ prevent instantiation :-)
94
94
NestedCheckedException nex = new NestedCheckedException (myMessage , rootCause ) {};
95
95
assertEquals (nex .getCause (), rootCause );
96
- assertTrue (nex .getMessage ().indexOf (myMessage ) != - 1 );
97
- assertTrue (nex .getMessage ().indexOf ( rootCauseMesg ) != - 1 );
96
+ assertTrue (nex .getMessage ().contains (myMessage ));
97
+ assertTrue (nex .getMessage ().endsWith ( rootCauseMsg ) );
98
98
99
99
// check PrintStackTrace
100
100
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
101
101
PrintWriter pw = new PrintWriter (baos );
102
102
nex .printStackTrace (pw );
103
103
pw .flush ();
104
104
String stackTrace = new String (baos .toByteArray ());
105
- assertFalse (stackTrace .indexOf (rootCause .getClass ().getName ()) == - 1 );
106
- assertFalse (stackTrace .indexOf ( rootCauseMesg ) == - 1 );
105
+ assertTrue (stackTrace .contains (rootCause .getClass ().getName ()));
106
+ assertTrue (stackTrace .contains ( rootCauseMsg ) );
107
107
}
108
108
109
109
}
0 commit comments