RootCauseFinder improvements
This commit is contained in:
parent
6da90b24b0
commit
c2d94513d8
|
@ -454,7 +454,7 @@
|
||||||
<gson.version>2.8.2</gson.version>
|
<gson.version>2.8.2</gson.version>
|
||||||
|
|
||||||
<!-- util -->
|
<!-- 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-io.version>2.5</commons-io.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<decimal4j.version>1.0.3</decimal4j.version>
|
<decimal4j.version>1.0.3</decimal4j.version>
|
||||||
|
|
|
@ -10,10 +10,13 @@ import java.util.Objects;
|
||||||
*/
|
*/
|
||||||
public class RootCauseFinder {
|
public class RootCauseFinder {
|
||||||
|
|
||||||
|
private RootCauseFinder() {
|
||||||
|
}
|
||||||
|
|
||||||
public static Throwable findCauseUsingPlainJava(Throwable throwable) {
|
public static Throwable findCauseUsingPlainJava(Throwable throwable) {
|
||||||
Objects.requireNonNull(throwable);
|
Objects.requireNonNull(throwable);
|
||||||
Throwable rootCause = throwable;
|
Throwable rootCause = throwable;
|
||||||
while (rootCause.getCause() != null) {
|
while (rootCause.getCause() != null && rootCause.getCause() != rootCause) {
|
||||||
rootCause = rootCause.getCause();
|
rootCause = rootCause.getCause();
|
||||||
}
|
}
|
||||||
return rootCause;
|
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
|
@Test
|
||||||
public void givenWrongFormatDate_whenFindingRootCauseUsingGuava_thenRootCauseFound() {
|
public void givenWrongFormatDate_whenFindingRootCauseUsingGuava_thenRootCauseFound() {
|
||||||
try {
|
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