1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.utils;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.internal.utils.TestUtil.isUtilsClassHasPrivateConstructor;
24
25 import java.io.File;
26 import java.util.UUID;
27
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.io.TempDir;
30
31 public class FilterUtilTest {
32
33 @TempDir
34 public File temporaryFolder;
35
36 @Test
37 public void testIsProperUtilsClass() throws ReflectiveOperationException {
38 assertWithMessage("Constructor is not private")
39 .that(isUtilsClassHasPrivateConstructor(FilterUtil.class))
40 .isTrue();
41 }
42
43 @Test
44 public void testExistingFile() throws Exception {
45 final String uniqueFileName = "junit_" + UUID.randomUUID() + ".java";
46 final File file = new File(temporaryFolder, uniqueFileName);
47 file.createNewFile();
48 assertWithMessage("Suppression file exists")
49 .that(FilterUtil.isFileExists(file.getPath()))
50 .isTrue();
51 }
52
53 @Test
54 public void testNonExistentFile() {
55 assertWithMessage("Suppression file does not exist")
56 .that(FilterUtil.isFileExists("non-existent.xml"))
57 .isFalse();
58 }
59
60 }