Add unit tests for welcome info
This commit is contained in:
parent
faa7e43891
commit
bc2a39c2e0
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<property file="resources/build.properties" />
|
<property file="resources/build.properties" />
|
||||||
|
|
||||||
|
<property name="root.dir" value=".."/> <!-- Root directory -->
|
||||||
<property name="src.dir" value="${basedir}/src"/> <!-- Source directory -->
|
<property name="src.dir" value="${basedir}/src"/> <!-- Source directory -->
|
||||||
<property name="src-test.dir" value="${basedir}/test"/> <!-- Test directory -->
|
<property name="src-test.dir" value="${basedir}/test"/> <!-- Test directory -->
|
||||||
<property name="build.dir" value="${basedir}/build"/> <!-- Build directory -->
|
<property name="build.dir" value="${basedir}/build"/> <!-- Build directory -->
|
||||||
@ -34,6 +35,7 @@
|
|||||||
<pathelement location="${build-test.dir}"/>
|
<pathelement location="${build-test.dir}"/>
|
||||||
<pathelement location="${classes.dir}"/>
|
<pathelement location="${classes.dir}"/>
|
||||||
<pathelement location="${src-test.dir}"/>
|
<pathelement location="${src-test.dir}"/>
|
||||||
|
<pathelement location="${root.dir}"/>
|
||||||
<fileset dir="${libtest.dir}/" includes="*.jar"/>
|
<fileset dir="${libtest.dir}/" includes="*.jar"/>
|
||||||
</path>
|
</path>
|
||||||
|
|
||||||
|
@ -6,22 +6,26 @@ import net.sf.openrocket.util.BuildProperties;
|
|||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
public abstract class WelcomeInfoRetriever {
|
public abstract class WelcomeInfoRetriever {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the release notes of the current build version from the ReleaseNotes.md file.
|
* Retrieves the release notes of the current build version from the ReleaseNotes.md file.
|
||||||
|
* @param version the build version to search the release notes for (e.g. "22.02")
|
||||||
* @return the release notes of the current build version
|
* @return the release notes of the current build version
|
||||||
* @throws IOException if the file could not be read
|
* @throws IOException if the file could not be read
|
||||||
*/
|
*/
|
||||||
public static String retrieveWelcomeInfo() throws IOException {
|
public static String retrieveWelcomeInfo(String version) throws IOException {
|
||||||
InputStream in = new FileInputStream("ReleaseNotes.md");
|
ClassLoader cl = WelcomeInfoRetriever.class.getClassLoader();
|
||||||
|
InputStream in = cl.getResourceAsStream("ReleaseNotes.md");
|
||||||
|
if (in == null) {
|
||||||
|
throw new FileNotFoundException("ReleaseNotes.md not found");
|
||||||
|
}
|
||||||
InputSource source = new InputSource(new InputStreamReader(in));
|
InputSource source = new InputSource(new InputStreamReader(in));
|
||||||
ReleaseNotesHandler handler = new ReleaseNotesHandler(BuildProperties.getVersion());
|
ReleaseNotesHandler handler = new ReleaseNotesHandler(version);
|
||||||
WarningSet warnings = new WarningSet();
|
WarningSet warnings = new WarningSet();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -31,4 +35,13 @@ public abstract class WelcomeInfoRetriever {
|
|||||||
throw new IOException(e.getMessage(), e);
|
throw new IOException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the release notes of the current build version from the ReleaseNotes.md file.
|
||||||
|
* @return the release notes of the current build version
|
||||||
|
* @throws IOException if the file could not be read
|
||||||
|
*/
|
||||||
|
public static String retrieveWelcomeInfo() throws IOException {
|
||||||
|
return retrieveWelcomeInfo(BuildProperties.getVersion());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package net.sf.openrocket.communication;
|
||||||
|
|
||||||
|
import net.sf.openrocket.util.BaseTestCase.BaseTestCase;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class WelcomeInfoTest extends BaseTestCase {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: this unit test will fail if you don't run it using 'ant unittest', because otherwise
|
||||||
|
* it can't load the ReleaseNotes.md file.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testWelcomeInfo() throws Exception {
|
||||||
|
// Test the welcome info for the current build version
|
||||||
|
String welcomeInfo = WelcomeInfoRetriever.retrieveWelcomeInfo();
|
||||||
|
assertNotNull(welcomeInfo);
|
||||||
|
assertTrue(welcomeInfo.length() > 0);
|
||||||
|
|
||||||
|
// Test the release info for a bogus release version
|
||||||
|
welcomeInfo = WelcomeInfoRetriever.retrieveWelcomeInfo("bogus release");
|
||||||
|
assertNull(welcomeInfo);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user