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

AuthMe / ConfigMe / 6022426951

30 Aug 2023 08:26AM UTC coverage: 97.279% (+3.7%) from 93.592%
6022426951

push

github

ljacqu
Draft: collection property types (3)

528 of 546 branches covered (0.0%)

45 of 45 new or added lines in 12 files covered. (100.0%)

1466 of 1507 relevant lines covered (97.28%)

4.44 hits per line

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

82.35
/src/main/java/ch/jalu/configme/utils/Utils.java
1
package ch.jalu.configme.utils;
2

3
import ch.jalu.configme.exception.ConfigMeException;
4
import org.jetbrains.annotations.NotNull;
5

6
import java.io.IOException;
7
import java.lang.reflect.Array;
8
import java.nio.file.Files;
9
import java.nio.file.Path;
10

11
/**
12
 * Utilities class.
13
 */
14
public final class Utils {
15

16
    private Utils() {
17
    }
18

19
    /**
20
     * Attempts to create the given Path (as file) if it doesn't exist. If creating the file
21
     * is unsuccessful, an exception is thrown. If the given path exists but is not a file,
22
     * an exception is thrown, too.
23
     *
24
     * @param file the file to create if it doesn't exist
25
     */
26
    public static void createFileIfNotExists(@NotNull Path file) {
27
        if (Files.exists(file)) {
5✔
28
            if (!Files.isRegularFile(file)) {
5✔
29
                throw new ConfigMeException("Expected file but '" + file + "' is not a file");
14✔
30
            }
31
        } else {
32
            Path parent = file.getParent();
3✔
33
            if (!Files.exists(parent) || !Files.isDirectory(parent)) {
10✔
34
                try {
35
                    Files.createDirectories(parent);
5✔
36
                } catch (IOException e) {
1✔
37
                    throw new ConfigMeException("Failed to create parent folders for '" + file + "'", e);
15✔
38
                }
1✔
39
            }
40
            try {
41
                Files.createFile(file);
5✔
42
            } catch (IOException e) {
1✔
43
                throw new ConfigMeException("Failed to create file '" + file + "'", e);
15✔
44
            }
1✔
45
        }
46
    }
1✔
47

48
    @SuppressWarnings("unchecked")
49
    public static <T> T[] createArrayForReferenceType(Class<T> component, int size) {
50
        if (component.isPrimitive()) {
×
51
            throw new IllegalArgumentException("The component type may not be a primitive type");
×
52
        }
53
        return (T[]) Array.newInstance(component, size);
×
54
    }
55
}
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