Skip to content

Commit 6785a3f

Browse files
committed
Add tests and lint run target
1 parent ebb68f2 commit 6785a3f

File tree

6 files changed

+189
-3
lines changed

6 files changed

+189
-3
lines changed

.github/workflows/build-project.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
distribution: 'oracle'
1313
java-version: '23.0.1'
1414
- run: |
15-
mvn --batch-mode --update-snapshots verify
15+
mvn test
1616
1717
1818
build:
@@ -37,4 +37,14 @@ jobs:
3737
path: out/Bot/InsideAgentDev-${{env.RELEASE_VERSION}}.jar
3838

3939

40-
#lint:
40+
lint:
41+
runs-on: ubuntu-latest
42+
timeout-minutes: 2
43+
steps:
44+
- uses: actions/checkout@v4
45+
- uses: actions/setup-java@v4
46+
with:
47+
distribution: 'oracle'
48+
java-version: '23.0.1'
49+
- run: |
50+
mvn checkstyle:check

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
/target/
33
/src/main/resources/loginInfo.yml
44
/.idea/
5-
/src/test/
5+
/src/test/java/ApiTesting.java
66
/out/

dependency-reduced-pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
<artifactId>InsideAgentDev</artifactId>
66
<version>0.10.0</version>
77
<build>
8+
<testSourceDirectory>${project.basedir}/src/test/java/</testSourceDirectory>
89
<plugins>
10+
<plugin>
11+
<artifactId>maven-surefire-plugin</artifactId>
12+
<version>3.1.2</version>
13+
<configuration>
14+
<excludes />
15+
</configuration>
16+
</plugin>
917
<plugin>
1018
<artifactId>maven-compiler-plugin</artifactId>
1119
<version>3.10.1</version>
@@ -58,6 +66,25 @@
5866
<reportOutputDirectory>./docs/</reportOutputDirectory>
5967
</configuration>
6068
</plugin>
69+
<plugin>
70+
<artifactId>maven-checkstyle-plugin</artifactId>
71+
<version>3.6.0</version>
72+
<executions>
73+
<execution>
74+
<id>validate</id>
75+
<goals>
76+
<goal>check</goal>
77+
</goals>
78+
</execution>
79+
</executions>
80+
<configuration>
81+
<encoding>UTF-8</encoding>
82+
<consoleOutput>true</consoleOutput>
83+
<failsOnError>false</failsOnError>
84+
<failOnViolation>false</failOnViolation>
85+
<linkXRef>false</linkXRef>
86+
</configuration>
87+
</plugin>
6188
</plugins>
6289
</build>
6390
<repositories>
@@ -92,6 +119,26 @@
92119
<type>pom</type>
93120
<scope>test</scope>
94121
</dependency>
122+
<dependency>
123+
<groupId>org.junit.jupiter</groupId>
124+
<artifactId>junit-jupiter-engine</artifactId>
125+
<version>5.10.0</version>
126+
<scope>test</scope>
127+
<exclusions>
128+
<exclusion>
129+
<artifactId>junit-platform-engine</artifactId>
130+
<groupId>org.junit.platform</groupId>
131+
</exclusion>
132+
<exclusion>
133+
<artifactId>junit-jupiter-api</artifactId>
134+
<groupId>org.junit.jupiter</groupId>
135+
</exclusion>
136+
<exclusion>
137+
<artifactId>apiguardian-api</artifactId>
138+
<groupId>org.apiguardian</groupId>
139+
</exclusion>
140+
</exclusions>
141+
</dependency>
95142
</dependencies>
96143
<properties>
97144
<maven.compiler.target>17</maven.compiler.target>

pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,27 @@
8181
</configuration>
8282
</plugin>
8383

84+
<plugin>
85+
<groupId>org.apache.maven.plugins</groupId>
86+
<artifactId>maven-checkstyle-plugin</artifactId>
87+
<version>3.6.0</version>
88+
<configuration>
89+
<encoding>UTF-8</encoding>
90+
<consoleOutput>true</consoleOutput>
91+
<failsOnError>false</failsOnError>
92+
<failOnViolation>false</failOnViolation>
93+
<linkXRef>false</linkXRef>
94+
</configuration>
95+
<executions>
96+
<execution>
97+
<id>validate</id>
98+
<goals>
99+
<goal>check</goal>
100+
</goals>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
84105
</plugins>
85106
</build>
86107

src/test/java/unit/BasicTests.java

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package unit;
2+
3+
import dev.jacrispys.JavaBot.utils.SecretData;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.junit.jupiter.api.Test;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.io.ByteArrayOutputStream;
10+
import java.io.File;
11+
import java.io.IOException;
12+
import java.io.PrintStream;
13+
import java.lang.reflect.InvocationTargetException;
14+
import java.lang.reflect.Method;
15+
16+
public class BasicTests {
17+
18+
@Test
19+
void verifyTrue() {
20+
Assertions.assertTrue(true);
21+
}
22+
23+
@Test
24+
void verifyFalse() {
25+
Assertions.assertFalse(false);
26+
}
27+
28+
@Test
29+
void verifyInfoLogging() {
30+
final ByteArrayOutputStream out = new ByteArrayOutputStream();
31+
System.setOut(new PrintStream(out));
32+
33+
Logger logger = LoggerFactory.getLogger(BasicTests.class);
34+
logger.info("Hello, World!");
35+
36+
final String logMessage = out.toString();
37+
Assertions.assertTrue(logMessage.contains("Hello, World!"));
38+
39+
}
40+
41+
@Test
42+
void verifyDebugLogging() {
43+
final ByteArrayOutputStream out = new ByteArrayOutputStream();
44+
System.setOut(new PrintStream(out));
45+
46+
Logger logger = LoggerFactory.getLogger(BasicTests.class);
47+
logger.debug("Hello, World!");
48+
49+
final String logMessage = out.toString();
50+
Assertions.assertTrue(logMessage.contains("Hello, World!"));
51+
52+
}
53+
54+
@Test
55+
void verifyNoTraceLogging() {
56+
final ByteArrayOutputStream out = new ByteArrayOutputStream();
57+
System.setOut(new PrintStream(out));
58+
59+
Logger logger = LoggerFactory.getLogger(BasicTests.class);
60+
logger.trace("Hello, World!");
61+
62+
final String logMessage = out.toString();
63+
Assertions.assertFalse(logMessage.contains("Hello, World!"));
64+
65+
}
66+
67+
@Test
68+
void configGenerated() throws IOException, InvocationTargetException, IllegalAccessException, NoSuchMethodException {
69+
SecretData.initLoginInfo();
70+
Class<SecretData> clazz = SecretData.class;
71+
Method m = clazz.getDeclaredMethod("getClassPath");
72+
m.setAccessible(true);
73+
String classPath = (String) m.invoke(null);
74+
m.setAccessible(false);
75+
String path = classPath + File.separator + "config" + File.separator + "loginInfo.yml";
76+
File file = new File(path);
77+
Assertions.assertTrue(file.exists());
78+
}
79+
}
80+
81+
class TraceLoggingTest {
82+
@Test
83+
void verifyTraceLogging() {
84+
final ByteArrayOutputStream out = new ByteArrayOutputStream();
85+
System.setOut(new PrintStream(out));
86+
87+
Logger logger = LoggerFactory.getLogger(TraceLoggingTest.class);
88+
logger.trace("Hello, World!");
89+
90+
final String logMessage = out.toString();
91+
Assertions.assertTrue(logMessage.contains("Hello, World!"));
92+
93+
}
94+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<withJansi>false</withJansi>
5+
<encoder>
6+
<pattern>%d{HH:mm:ss.SSS} %boldCyan(%-34.-34thread) %red(%10.10X{jda.shard}) %boldGreen(%-15.-15logger{0}) %highlight(%-6level) %msg%n</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="DEBUG">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
<logger name="unit.TraceLoggingTest" level="TRACE"/>
14+
</configuration>

0 commit comments

Comments
 (0)