From 187aaf53c19ff8d3679957b9612d63e710d7a60c Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Mon, 13 Apr 2015 01:22:56 +0100 Subject: [PATCH] Start JUnit testing --- pom.xml | 2 +- src/test/java/wf/doyle/blockbuster/AppTest.java | 62 ++++++++++++++++++++++++++++++-------------------------------- target/test-classes/wf/doyle/blockbuster/AppTest.class | Bin 627 -> 1626 bytes 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/pom.xml b/pom.xml index e54eea8..4ccabc7 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ junit junit - 3.8.1 + 4.12 test diff --git a/src/test/java/wf/doyle/blockbuster/AppTest.java b/src/test/java/wf/doyle/blockbuster/AppTest.java index 9993855..b953dcd 100644 --- a/src/test/java/wf/doyle/blockbuster/AppTest.java +++ b/src/test/java/wf/doyle/blockbuster/AppTest.java @@ -1,38 +1,36 @@ package wf.doyle.blockbuster; -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; +import java.lang.reflect.Field; -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - /** - * Create the test case - * - * @param testName name of the test case - */ - public AppTest( String testName ) - { - super( testName ); - } +import org.junit.Assert; +import org.junit.Test; - /** - * @return the suite of tests being tested - */ - public static Test suite() - { - return new TestSuite( AppTest.class ); - } +import wf.doyle.blockbuster.file.FileReader; +import wf.doyle.blockbuster.item.LibraryItem; +import wf.doyle.blockbuster.item.items.audiovisual.DVD; - /** - * Rigourous Test :-) - */ - public void testApp() - { - assertTrue( true ); - } +/** + * Unit test for blockbuster + */ +public class AppTest { + /** + * + */ + @Test + public void assertReflection() { + LibraryItem item = new DVD(); + + Field f = FileReader.getField("title", item.getClass()); + + Assert.assertNotNull(f); + + LibraryItem i = FileReader.setField(f, item, "testCase"); + + try { + Assert.assertEquals(f.get(i), "testCase"); + } catch(Exception e) { + Assert.fail("Getting value of String using reflection failed"); + e.printStackTrace(System.err); + } + } } diff --git a/target/test-classes/wf/doyle/blockbuster/AppTest.class b/target/test-classes/wf/doyle/blockbuster/AppTest.class index 87f8bba..f01aa7b 100644 Binary files a/target/test-classes/wf/doyle/blockbuster/AppTest.class and b/target/test-classes/wf/doyle/blockbuster/AppTest.class differ -- libgit2 1.7.2