Permalink
Browse files

test for API drift, start to document API

  • Loading branch information...
1 parent c5e2b07 commit 76f64937f7580d9867db23981f1be65ee6f45afc @league committed Aug 19, 2009
Showing with 98 additions and 10 deletions.
  1. +4 −1 build.xml
  2. +51 −0 net/contrapunctus/lzma/ApiDriftTest.java
  3. +43 −9 net/contrapunctus/lzma/Version.template
View
@@ -48,7 +48,10 @@
</target>
<target name="javadoc" depends="init,version-stamp">
- <javadoc destdir="docs" classpath="${gentoo.classpath}">
+ <javadoc destdir="docs">
+ <classpath>
+ <path refid="test-path" />
+ </classpath>
<fileset dir=".">
<include name="**/*.java"/>
</fileset>
@@ -0,0 +1,51 @@
+package net.contrapunctus.lzma;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+/**
+ * A very simple set of tests to detect API drift over time.
+ * Essentially, we just access all the public classes, methods, and
+ * fields and check their types. Then, any changes that affect the
+ * API should cause a compilation error or test failure.
+ */
+public class ApiDriftTest
+{
+ /**
+ * Access the public API of the {@link Version} class.
+ */
+ @Test public void versionAPI()
+ {
+ int x = Version.major;
+ int y = Version.minor;
+ String s = Version.context;
+ Version.main(new String[0]);
+ Version.main(new String[1]);
+ }
+
+ /**
+ * Access the public API of the {@link LzmaOutputStream} class.
+ */
+ @Test public void outstreamAPI()
+ {
+ LzmaOutputStream.LZMA_HEADER = false;
+ LzmaOutputStream los;
+ los = new LzmaOutputStream(new ByteArrayOutputStream());
+ los = new LzmaOutputStream(new ByteArrayOutputStream(), 8, 2);
+ assertTrue(los instanceof OutputStream);
+ }
+
+ /**
+ * Access the public API of the {@link LzmaInputStream} class.
+ */
+ @Test public void instreamAPI()
+ {
+ LzmaInputStream lis;
+ lis = new LzmaInputStream(new ByteArrayInputStream(new byte[0]));
+ assertTrue(lis instanceof InputStream);
+ }
+}
@@ -1,13 +1,47 @@
+// -*- java -*-
package net.contrapunctus.lzma;
+
+import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.IOException;
-public class Version {
-public static final int major = @major@;
-public static final int minor = @minor@;
-public static final String context = "@context@";
-public static void main( String[] args ) {
- if( args.length > 0 ) System.out.println(context);
- else System.out.printf("lzmajio-%d.%d%n", major, minor);
- }
+
+/**
+ * Encapsulates version information about the library.
+ */
+public class Version
+{
+ /**
+ * The major version number, incremented rarely to indicate large
+ * changes.
+ */
+ public static final int major = @major@;
+
+ /**
+ * The minor version number, incremented to indicate bug fixes or
+ * other small changes.
+ */
+ public static final int minor = @minor@;
+
+ /**
+ * A unique string, representing this version in the code
+ * repository. Usually a combination of git tag and tree ID, as
+ * produced by <tt>git describe</tt>.
+ */
+ public static final String context = "@context@";
+
+ /**
+ * Private constructor, because there's no need to instantiate
+ * this class.
+ */
+ private Version() { }
+
+ /**
+ * Small main program that prints the library version or, with any
+ * argument, the context string.
+ */
+ public static void main( String[] args )
+ {
+ if( args.length > 0 ) System.out.println(context);
+ else System.out.printf("lzmajio-%d.%d%n", major, minor);
+ }
}

0 comments on commit 76f6493

Please sign in to comment.