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.api;
21
22 import static com.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.internal.utils.TestUtil.getExpectedThrowable;
24
25 import org.junit.jupiter.api.Test;
26
27 public class AuditEventTest {
28
29 @Test
30 public void test() {
31 final AuditEvent event = new AuditEvent(getClass());
32
33 assertWithMessage("invalid file name")
34 .that(event.getFileName())
35 .isNull();
36 assertWithMessage("invalid violation")
37 .that(event.getViolation())
38 .isNull();
39 assertWithMessage("invalid source")
40 .that(event.getSource())
41 .isEqualTo(getClass());
42 assertWithMessage("invalid severity")
43 .that(event.getSeverityLevel())
44 .isEqualTo(SeverityLevel.INFO);
45 }
46
47 @Test
48 public void testNoSource() {
49 final IllegalArgumentException ex = getExpectedThrowable(IllegalArgumentException.class,
50 () -> new AuditEvent(null),
51 "IllegalArgumentException expected");
52 assertWithMessage("Invalid exception message")
53 .that(ex.getMessage())
54 .isEqualTo("null source");
55 }
56
57 @Test
58 public void testFullConstructor() {
59 final Violation message = new Violation(1, 2, 3, "bundle", "key", null,
60 SeverityLevel.ERROR, "moduleId", getClass(), "customMessage");
61 final AuditEvent event = new AuditEvent(getClass(), "fileName", message);
62
63 assertWithMessage("invalid file name")
64 .that(event.getFileName())
65 .isEqualTo("fileName");
66 assertWithMessage("invalid violation")
67 .that(event.getViolation())
68 .isEqualTo(message);
69 assertWithMessage("invalid violation")
70 .that(event.getMessage())
71 .isEqualTo("customMessage");
72 assertWithMessage("invalid source")
73 .that(event.getSource())
74 .isEqualTo(getClass());
75 assertWithMessage("invalid line")
76 .that(event.getLine())
77 .isEqualTo(1);
78 assertWithMessage("invalid column")
79 .that(event.getColumn())
80 .isEqualTo(2);
81 assertWithMessage("invalid severity")
82 .that(event.getSeverityLevel())
83 .isEqualTo(SeverityLevel.ERROR);
84 assertWithMessage("invalid module id")
85 .that(event.getModuleId())
86 .isEqualTo("moduleId");
87 assertWithMessage("invalid source name")
88 .that(event.getSourceName())
89 .isEqualTo("com.puppycrawl.tools.checkstyle.api.AuditEventTest");
90 }
91 }