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

skuzzle / snapshot-tests / 1

12 Feb 2025 03:38PM UTC coverage: 86.61% (+0.03%) from 86.577%
1

Pull #109

jenkins

skuzzle
Remove old file after merge
Pull Request #109: 2.0 dev

1947 of 2248 relevant lines covered (86.61%)

0.87 hits per line

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

76.19
/../snapshot-tests-core/src/main/java/de/skuzzle/test/snapshots/impl/DetermineSnapshotDirectory.java
1
package de.skuzzle.test.snapshots.impl;
2

3
import java.nio.file.Path;
4

5
import de.skuzzle.test.snapshots.SnapshotDirectory;
6
import de.skuzzle.test.snapshots.SnapshotDirectoryStrategy;
7
import de.skuzzle.test.snapshots.SnapshotException;
8
import de.skuzzle.test.snapshots.io.DirectoryResolver;
9
import de.skuzzle.test.snapshots.validation.State;
10

11
final class DetermineSnapshotDirectory {
12

13
    static Path forTestclass(TestClass testClass) {
14
        final SnapshotDirectory annotation = testClass.getAnnotation(SnapshotDirectory.class);
1✔
15
        if (annotation == null) {
1✔
16
            // default behavior if no annotation is present
17
            final String dirName = testClass.getName().replace('.', '/') + "_snapshots";
1✔
18
            return DirectoryResolver.resolve(dirName);
1✔
19
        }
20

21
        State.check(!isDefaultValue(annotation.determinedBy()) || !annotation.value().isEmpty(),
1✔
22
                "Either specify the value() attribute or the determinedBy() attribute within the @SnapshotDirectory annotation on %s",
23
                testClass.getName());
1✔
24

25
        if (isDefaultValue(annotation.determinedBy())) {
1✔
26
            return DirectoryResolver.resolve(annotation.value());
1✔
27
        } else {
28
            return pathFromStrategy(testClass, annotation);
1✔
29
        }
30
    }
31

32
    private static boolean isDefaultValue(Class<?> type) {
33
        return "de.skuzzle.test.snapshots.DefaultSnapshotDirectoryStrategy".equals(type.getName());
1✔
34
    }
35

36
    private static Path pathFromStrategy(TestClass testClass, SnapshotDirectory directory) {
37
        try {
38
            final Path snapshotDirectory = newInstanceOf(directory.determinedBy())
1✔
39
                    .determineSnapshotDirectory(testClass.testClass(), directory);
1✔
40
            State.check(snapshotDirectory != null, "Custom SnapshotDirectoryStrategy %s returned null for %s",
1✔
41
                    directory.determinedBy().getName(), directory);
1✔
42
            return snapshotDirectory;
1✔
43
        } catch (final SnapshotException e) {
×
44
            throw new IllegalStateException(
×
45
                    "Error determining snapshot directory from strategy " + directory.determinedBy(), e);
×
46
        }
47
    }
48

49
    private static SnapshotDirectoryStrategy newInstanceOf(Class<? extends SnapshotDirectoryStrategy> type) {
50
        try {
51
            return type.getConstructor().newInstance();
1✔
52
        } catch (final Exception e) {
×
53
            throw new IllegalStateException("Error creating an instance of " + type.getName(), e);
×
54
        }
55
    }
56

57
    private DetermineSnapshotDirectory() {
58
        // hidden
59
    }
60
}
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

© 2026 Coveralls, Inc