Skip to content

Commit

Permalink
Added initial unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ao-apps committed Sep 17, 2023
1 parent e76385a commit 412a243
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def upstreamProjects = [
'servlet', // <groupId>com.semanticcms</groupId><artifactId>semanticcms-core-servlet</artifactId>
// No Jenkins: <groupId>com.github.spotbugs</groupId><artifactId>spotbugs-annotations</artifactId>

// Test Direct
// No Jenkins: <groupId>junit</groupId><artifactId>junit</artifactId>

// BOM
'../../oss/javaee-web-api-bom', // <groupId>com.aoapps</groupId><artifactId>javaee-web-api-bom</artifactId>
]
Expand Down
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ along with semanticcms-core-sitemap. If not, see <https://www.gnu.org/licenses/
<includes>element-list, package-list</includes>
<outputDirectory>${project.build.directory}/offlineLinks/com.github.spotbugs/spotbugs-annotations</outputDirectory>
</artifactItem>
<!-- Test Direct -->
<artifactItem>
<groupId>junit</groupId><artifactId>junit</artifactId><classifier>javadoc</classifier>
<includes>element-list, package-list</includes>
<outputDirectory>${project.build.directory}/offlineLinks/junit/junit</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
Expand Down Expand Up @@ -255,6 +261,11 @@ along with semanticcms-core-sitemap. If not, see <https://www.gnu.org/licenses/
<url>https://javadoc.io/doc/com.github.spotbugs/spotbugs-annotations/${spotbugs-annotations.version}/</url>
<location>${project.build.directory}/offlineLinks/com.github.spotbugs/spotbugs-annotations</location>
</offlineLink>
<!-- Test Direct -->
<offlineLink>
<url>https://junit.org/junit4/javadoc/latest/</url>
<location>${project.build.directory}/offlineLinks/junit/junit</location>
</offlineLink>
</offlineLinks>
</configuration>
</plugin>
Expand Down Expand Up @@ -398,6 +409,18 @@ along with semanticcms-core-sitemap. If not, see <https://www.gnu.org/licenses/
<dependency>
<groupId>com.google.code.findbugs</groupId><artifactId>jsr305</artifactId><version>3.0.2</version>
</dependency>
<!-- Test Direct -->
<dependency>
<groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version>
</dependency>
<!-- Test Transitive -->
<dependency>
<groupId>org.hamcrest</groupId><artifactId>hamcrest</artifactId><version>2.2</version>
</dependency>
<dependency>
<!-- Shim for junit 4.13.2 -->
<groupId>org.hamcrest</groupId><artifactId>hamcrest-core</artifactId><version>2.2</version>
</dependency>
<!-- Imports -->
<dependency>
<groupId>com.aoapps</groupId><artifactId>javaee-web-api-bom</artifactId><version>7.0.1-POST-SNAPSHOT</version>
Expand Down Expand Up @@ -452,6 +475,11 @@ along with semanticcms-core-sitemap. If not, see <https://www.gnu.org/licenses/
<groupId>com.github.spotbugs</groupId><artifactId>spotbugs-annotations</artifactId>
<optional>true</optional>
</dependency>
<!-- Test Direct -->
<dependency>
<groupId>junit</groupId><artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Imports (Reactor build order only) -->
<dependency>
<groupId>com.aoapps</groupId><artifactId>javaee-web-api-bom</artifactId><version>7.0.1-POST-SNAPSHOT</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,8 @@ public class SiteMapRobotsTxtServlet extends HttpServlet {

static {
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if (cl == null) {
cl = ClassLoader.getSystemClassLoader();
}
String classFilename = '/' + SiteMapRobotsTxtServlet.class.getName().replace('.', '/') + ".class";
URL classFile = cl.getResource(classFilename);
String classFilename = SiteMapRobotsTxtServlet.class.getSimpleName() + ".class";
URL classFile = SiteMapRobotsTxtServlet.class.getResource(classFilename);
if (classFile == null) {
throw new IOException("Unable to find class file: " + classFilename);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* semanticcms-core-sitemap - Automatic sitemaps for SemanticCMS.
* Copyright (C) 2023 AO Industries, Inc.
* support@aoindustries.com
* 7262 Bull Pen Cir
* Mobile, AL 36695
*
* This file is part of semanticcms-core-sitemap.
*
* semanticcms-core-sitemap is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* semanticcms-core-sitemap is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with semanticcms-core-sitemap. If not, see <https://www.gnu.org/licenses/>.
*/

package com.semanticcms.core.sitemap;

import static org.junit.Assert.assertNotEquals;

import java.lang.reflect.Field;
import org.junit.Test;

/**
* Tests {@link SiteMapRobotsTxtServlet}.
*/
public class SiteMapRobotsTxtServletTest {

private static long getLastModified() throws ReflectiveOperationException {
Field field = SiteMapRobotsTxtServlet.class.getDeclaredField("LAST_MODIFIED");
field.setAccessible(true);
return (long) field.get(null);
}

/**
* Tests {@link SiteMapRobotsTxtServlet#LAST_MODIFIED}.
*/
@Test
public void testLastModified() throws ReflectiveOperationException {
assertNotEquals(0, getLastModified());
}
}

0 comments on commit 412a243

Please sign in to comment.