RootCauseFinder improvements
This commit is contained in:
parent
6da90b24b0
commit
c2d94513d8
|
@ -454,7 +454,7 @@
|
|||
<gson.version>2.8.2</gson.version>
|
||||
|
||||
<!-- util -->
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<commons-lang3.version>3.9</commons-lang3.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<decimal4j.version>1.0.3</decimal4j.version>
|
||||
|
|
|
@ -10,10 +10,13 @@ import java.util.Objects;
|
|||
*/
|
||||
public class RootCauseFinder {
|
||||
|
||||
private RootCauseFinder() {
|
||||
}
|
||||
|
||||
public static Throwable findCauseUsingPlainJava(Throwable throwable) {
|
||||
Objects.requireNonNull(throwable);
|
||||
Throwable rootCause = throwable;
|
||||
while (rootCause.getCause() != null) {
|
||||
while (rootCause.getCause() != null && rootCause.getCause() != rootCause) {
|
||||
rootCause = rootCause.getCause();
|
||||
}
|
||||
return rootCause;
|
||||
|
|
|
@ -75,6 +75,15 @@ public class RootCauseFinderTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNullDate_whenFindingRootCauseUsingApacheCommons_thenRootCauseNotFound() {
|
||||
try {
|
||||
AgeCalculator.calculateAge(null);
|
||||
} catch (Exception ex) {
|
||||
assertTrue(ExceptionUtils.getRootCause(ex) instanceof IllegalArgumentException);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWrongFormatDate_whenFindingRootCauseUsingGuava_thenRootCauseFound() {
|
||||
try {
|
||||
|
@ -93,4 +102,13 @@ public class RootCauseFinderTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNullDate_whenFindingRootCauseUsingGuava_thenRootCauseFound() {
|
||||
try {
|
||||
AgeCalculator.calculateAge(null);
|
||||
} catch (Exception ex) {
|
||||
assertTrue(Throwables.getRootCause(ex) instanceof IllegalArgumentException);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue