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

coditory / quark-config / #35

pending completion
#35

push

github-actions

ogesaku
Update dependencies and add config.audit/auditMap methods

14 of 14 new or added lines in 2 files covered. (100.0%)

1330 of 1842 relevant lines covered (72.2%)

0.72 hits per line

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

75.61
/src/main/java/com/coditory/quark/config/AuditableConfig.java
1
package com.coditory.quark.config;
2

3
import org.jetbrains.annotations.NotNull;
4

5
import java.util.List;
6
import java.util.Map;
7
import java.util.Map.Entry;
8
import java.util.Objects;
9
import java.util.Optional;
10
import java.util.stream.Collectors;
11

12
import static com.coditory.quark.config.ConfigRemoveOptions.removeEmptyParents;
13

14
public final class AuditableConfig extends ConfigDecorator {
15
    private static final Object USED_MARKER = new Object();
1✔
16
    private Config unreadConfig;
17

18
    static AuditableConfig of(Config config) {
19
        if (config instanceof AuditableConfig) {
1✔
20
            return (AuditableConfig) config;
×
21
        }
22
        return new AuditableConfig(config);
1✔
23
    }
24

25
    AuditableConfig(Config config) {
26
        super(config);
1✔
27
        this.unreadConfig = config;
1✔
28
    }
1✔
29

30
    @NotNull
31
    @Override
32
    public Config getSubConfig(@NotNull String path) {
33
        markAsUsedProperty(path);
1✔
34
        return super.getSubConfig(path);
1✔
35
    }
36

37
    @NotNull
38
    @Override
39
    public Config getSubConfigOrEmpty(@NotNull String path) {
40
        markAsUsedProperty(path);
×
41
        return super.getSubConfigOrEmpty(path);
×
42
    }
43

44
    @NotNull
45
    @Override
46
    public Config getSubConfig(@NotNull String path, @NotNull Config defaultValue) {
47
        markAsUsedProperty(path);
×
48
        return super.getSubConfig(path, defaultValue);
×
49
    }
50

51
    @NotNull
52
    @Override
53
    public Optional<Config> getSubConfigAsOptional(@NotNull String path) {
54
        markAsUsedProperty(path);
×
55
        return super.getSubConfigAsOptional(path);
×
56
    }
57

58
    @NotNull
59
    @Override
60
    public <T> Optional<List<T>> getListAsOptional(@NotNull Class<T> type, @NotNull String path) {
61
        markAsUsedProperty(path);
×
62
        return super.getListAsOptional(type, path);
×
63
    }
64

65
    @NotNull
66
    @Override
67
    public <T> Optional<T> getAsOptional(@NotNull Class<T> type, @NotNull String path) {
68
        markAsUsedProperty(path);
1✔
69
        return super.getAsOptional(type, path);
1✔
70
    }
71

72
    @NotNull
73
    public AuditableConfig markAsUsedProperty(@NotNull String path) {
74
        if (unreadConfig.contains(path)) {
1✔
75
            unreadConfig = Config.builder(unreadConfig)
1✔
76
                    .put(path, USED_MARKER)
1✔
77
                    .build();
1✔
78
        }
79
        return this;
1✔
80
    }
81

82
    @NotNull
83
    public Config getUnusedProperties() {
84
        return Config.builder()
1✔
85
                .putAll(unreadConfig)
1✔
86
                .filterValues(
1✔
87
                        (path, value) -> !Objects.equals(value, USED_MARKER),
1✔
88
                        removeEmptyParents()
1✔
89
                ).build();
1✔
90
    }
91

92
    public void failOnUnusedProperties() {
93
        Map<String, Object> properties = unreadConfig.toFlatMap().entrySet().stream()
1✔
94
                .filter(entry -> entry.getValue() != USED_MARKER)
1✔
95
                .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
1✔
96
        if (!properties.isEmpty()) {
1✔
97
            int limit = 5;
1✔
98
            List<String> names = properties.keySet().stream().sorted().toList();
1✔
99
            String limitedNames = names.stream().limit(5).collect(Collectors.joining("\n"));
1✔
100
            if (names.size() > limit) {
1✔
101
                limitedNames = limitedNames + "\n...";
×
102
            }
103
            throw new ConfigUnusedPropertiesException("Detected unused config properties:\n" + limitedNames);
1✔
104
        }
105
    }
1✔
106
}
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