|
1 | 1 | package com.sap.hcp.cf.logging.common;
|
2 | 2 |
|
3 | 3 | import static com.sap.hcp.cf.logging.common.converter.CustomFieldMatchers.hasCustomField;
|
| 4 | +import static java.util.Arrays.asList; |
4 | 5 | import static org.hamcrest.MatcherAssert.assertThat;
|
5 |
| -import static org.hamcrest.Matchers.contains; |
6 |
| -import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
7 |
| -import static org.hamcrest.Matchers.lessThanOrEqualTo; |
| 6 | +import static org.hamcrest.Matchers.*; |
8 | 7 | import static org.hamcrest.core.Is.is;
|
9 | 8 | import static org.hamcrest.core.IsNull.notNullValue;
|
10 | 9 |
|
@@ -122,20 +121,17 @@ public void testCustomFieldOverwritesMdc() throws Exception {
|
122 | 121 | assertThat(getField(SOME_KEY), is(SOME_OTHER_VALUE));
|
123 | 122 | }
|
124 | 123 |
|
125 |
| - @Test |
| 124 | + @Test |
126 | 125 | public void testStacktrace() {
|
127 |
| - try { |
128 |
| - Double.parseDouble(null); |
129 |
| - } catch (Exception ex) { |
130 |
| - logMsg = "Running testStacktrace()"; |
131 |
| - LOGGER.error(logMsg, ex); |
132 |
| - assertThat(getMessage(), is(logMsg)); |
133 |
| - assertThat(getField(Fields.COMPONENT_ID), is("-")); |
134 |
| - assertThat(getField(Fields.COMPONENT_NAME), is("-")); |
135 |
| - assertThat(getField(Fields.COMPONENT_INSTANCE), is("0")); |
136 |
| - assertThat(getField(Fields.STACKTRACE), is(notNullValue())); |
137 |
| - assertThat(getField(Fields.WRITTEN_TS), is(notNullValue())); |
138 |
| - } |
| 126 | + logMsg = "Running testStacktrace()"; |
| 127 | + Exception testEx = new Exception("Test-case for Stacktraces."); |
| 128 | + LOGGER.error(logMsg, testEx); |
| 129 | + assertThat(getMessage(), is(logMsg)); |
| 130 | + assertThat(getField(Fields.COMPONENT_ID), is("-")); |
| 131 | + assertThat(getField(Fields.COMPONENT_NAME), is("-")); |
| 132 | + assertThat(getField(Fields.COMPONENT_INSTANCE), is("0")); |
| 133 | + assertThat(getField(Fields.STACKTRACE), stringContainsInOrder(asList("java.lang.Exception", "Test-case for Stacktraces."))); |
| 134 | + assertThat(getField(Fields.WRITTEN_TS), is(notNullValue())); |
139 | 135 | }
|
140 | 136 |
|
141 | 137 | @Test
|
|
0 commit comments