• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

coditory / quark-uri / #3

pending completion
#3

push

github-actions

ogesaku
init

1212 of 1212 new or added lines in 21 files covered. (100.0%)

926 of 1212 relevant lines covered (76.4%)

0.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.47
/src/main/java/com/coditory/quark/uri/Throwables.java
1
package com.coditory.quark.uri;
2

3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.HashSet;
6
import java.util.List;
7
import java.util.Set;
8

9
import static com.coditory.quark.uri.Preconditions.expectNonNull;
10

11
final class Throwables {
12
    private Throwables() {
×
13
        throw new UnsupportedOperationException("Do not instantiate utility class");
×
14
    }
15

16
    @SuppressWarnings("unchecked")
17
    static <T extends Throwable> T getRootCauseOfType(Throwable throwable, Class<T> type) {
18
        expectNonNull(throwable, "throwable");
1✔
19
        expectNonNull(type, "type");
1✔
20
        List<Throwable> list = getCauses(throwable);
1✔
21
        Collections.reverse(list);
1✔
22
        Throwable result = list.stream()
1✔
23
                .filter(type::isInstance)
1✔
24
                .findFirst()
1✔
25
                .orElse(null);
1✔
26
        return (T) result;
1✔
27
    }
28

29
    static List<Throwable> getCauses(Throwable throwable) {
30
        expectNonNull(throwable, "throwable");
1✔
31
        List<Throwable> list = new ArrayList<>();
1✔
32
        Set<Throwable> visited = new HashSet<>();
1✔
33
        while (throwable != null && !visited.contains(throwable)) {
1✔
34
            list.add(throwable);
1✔
35
            visited.add(throwable);
1✔
36
            throwable = throwable.getCause();
1✔
37
        }
38
        return list;
1✔
39
    }
40
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc