Skip to content

Commit

Permalink
Add test case for stefanbirkner/system-rules#8.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbirkner committed Aug 30, 2013
1 parent ea54965 commit bcf1fcb
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
61 changes: 61 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0"?>
<project name="java-junit-template-project" default="test" basedir=".">
<!-- build all classes in this directory -->

<property name="main.build.dir" value="build/main" />
<property name="main.src.dir" value="src" />
<property name="test.build.dir" value="build/test" />
<property name="test.src.dir" value="test" />

<path id="classpath.base" />

<path id="classpath.test">
<pathelement location="lib/junit-4.11.jar" />
<pathelement location="lib/hamcrest-core-1.3.jar" />
<pathelement location="lib/system-rules-1.3.1.jar" />
<pathelement location="${main.build.dir}"/>
<path refid="classpath.base" />
</path>

<target name="test" depends="run, clean" />

<target name="compile">
<mkdir dir="${main.build.dir}"/>
<javac srcdir="${main.src.dir}" destdir="${main.build.dir}" includeantruntime="false">
<classpath refid="classpath.base"/>
</javac>
</target>

<target name="build" depends="compile">
<mkdir dir="${test.build.dir}"/>
<javac srcdir="${test.src.dir}" destdir="${test.build.dir}" includeantruntime="false">
<classpath refid="classpath.test"/>
</javac>
<echo message="Build done" />
</target>

<!-- Test and build all files -->
<!-- To run this: use "ant" (default) or "ant run" -->
<target name="run" depends="build">
<junit printsummary="on" haltonfailure="yes" failureProperty="test.failure">
<classpath>
<path refid="classpath.test" />
<pathelement location="${test.build.dir}"/>
</classpath>
<formatter type="brief" usefile="false" />
<batchtest>
<fileset dir="${test.src.dir}" includes="**/*Test*.java" />
</batchtest>
</junit>
<fail message="test failed" if="test.failure" />
</target>

<!-- delete all class files -->
<!-- To run this: use "ant clean" -->
<target name="clean">
<delete>
<fileset dir="${basedir}" includes="**/*.class" />
</delete>
<echo message="clean done" />
</target>
</project>
12 changes: 12 additions & 0 deletions src/uk/co/placona/helloWorld/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package uk.co.placona.helloWorld;

public class HelloWorld {

public String sayHello() {
return "Hello World";
}

public void printHello() {
System.out.print(sayHello());
}
}
27 changes: 27 additions & 0 deletions test/helloWorld/HelloWorldTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package helloWorld;

import static org.junit.Assert.*;

import org.junit.*;
import org.junit.contrib.java.lang.system.StandardOutputStreamLog;
import uk.co.placona.helloWorld.HelloWorld;


public class HelloWorldTest {

@Rule
public final StandardOutputStreamLog log = new StandardOutputStreamLog();

@Test
public void testHellowWorld(){
HelloWorld hello = new HelloWorld();
assertEquals("A test for Hello World String", "Hello World", hello.sayHello());
}

@Test
public void printsHelloWorld() {
HelloWorld hello = new HelloWorld();
hello.printHello();
assertEquals("Wrong output", "Hello World", log.getLog());
}
}

0 comments on commit bcf1fcb

Please sign in to comment.