commit 9f5b6bce69638b3f2f1d336e57c9ee65395678fa
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Wed May 4 16:12:06 2011 +0000

    writing test classes simplified

diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/junit/DataPortalContextSuite.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/junit/DataPortalContextSuite.java
index 07ee039b..03a18234 100644
--- a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/junit/DataPortalContextSuite.java
+++ b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/main/java/eu/etaxonomy/dataportal/junit/DataPortalContextSuite.java
@@ -1,5 +1,5 @@
 /**
- * 
+ *
  */
 package eu.etaxonomy.dataportal.junit;
 
@@ -14,9 +14,11 @@ import org.junit.runners.Suite;
 import org.junit.runners.model.FrameworkMethod;
 import org.junit.runners.model.InitializationError;
 import org.junit.runners.model.Statement;
+import org.junit.runners.model.TestClass;
 
 import eu.etaxonomy.dataportal.DataPortalContext;
 import eu.etaxonomy.dataportal.DataPortalContexts;
+import eu.etaxonomy.dataportal.selenium.CdmDataPortalTestBase;
 
 
 /**
@@ -26,12 +28,12 @@ import eu.etaxonomy.dataportal.DataPortalContexts;
 public class DataPortalContextSuite extends Suite{
 
 	private final List<Runner> runners = new ArrayList<Runner>();
-	
-	
+
+
 	private class TestClassRunnerWithDataPortalContext extends
 	BlockJUnit4ClassRunner {
-		
-		private DataPortalContext context;
+
+		private final DataPortalContext context;
 
 		/**
 		 * @param klass
@@ -41,12 +43,14 @@ public class DataPortalContextSuite extends Suite{
 			super(klass);
 			this.context = context;
 		}
-		
+
 		@Override
 		public Object createTest() throws Exception {
-			return getTestClass().getOnlyConstructor().newInstance(context);
+			Object testClass = getTestClass().getOnlyConstructor().newInstance();
+			((CdmDataPortalTestBase)testClass).setContext(context);
+			return testClass;
 		}
-		
+
 		@Override
 		protected String getName() {
 			return String.format("%s@%s", getTestClass().getName(), context.name());
@@ -55,27 +59,27 @@ public class DataPortalContextSuite extends Suite{
 		@Override
 		protected String testName(final FrameworkMethod method) {
 			return String.format("%s@%s", method.getName(), context.name());
-		
+
 		}
-		
+
 		@Override
 		protected Statement classBlock(RunNotifier notifier) {
 			return childrenInvoker(notifier);
 		}
-		
+
 		@Override
 		protected void validateZeroArgConstructor(List<Throwable> errors) {
+			super.validateZeroArgConstructor(errors);
+			validateCdmDataPortalTestBase(errors);
+		}
+
+		protected void validateCdmDataPortalTestBase(List<Throwable> errors) {
 			// constructor should have exactly one arg
-			if (hasOneConstructor()
-					&& !(getTestClass().getOnlyConstructor().getParameterTypes().length == 1)) {
-				String gripe= "Test class should have exactly one public constructor with DataPortalContext as argument";
+			if ( ! CdmDataPortalTestBase.class.isAssignableFrom(getTestClass().getJavaClass()) ){
+				String gripe= "Test class must be a subclass of " + CdmDataPortalTestBase.class.getName();
 				errors.add(new Exception(gripe));
 			}
 		}
-		
-		private boolean hasOneConstructor() {
-			return getTestClass().getJavaClass().getConstructors().length == 1;
-		}
 	}
 
 	/**
@@ -88,7 +92,7 @@ public class DataPortalContextSuite extends Suite{
 			runners.add(new TestClassRunnerWithDataPortalContext(klass, cntxt));
 		}
 	}
-	
+
 	@Override
 	protected List<Runner> getChildren() {
 		return runners;
diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalSeleniumRCTestBase.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalSeleniumRCTestBase.java
index 006f02f8..a2262548 100644
--- a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalSeleniumRCTestBase.java
+++ b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalSeleniumRCTestBase.java
@@ -1,9 +1,9 @@
 // $Id$
 /**
  * Copyright (C) 2009 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -22,7 +22,7 @@ import eu.etaxonomy.dataportal.DataPortalManager;
 
 /**
  * http://seleniumhq.org/docs/03_webdriver.html#emulating-selenium-rc
- * 
+ *
  * @author a.kohlbecker
  * @deprecated SeleniumRCTests should only be used if you are really desperatly
  *             shor in time and you need to use the Selenium 1 IDE in order to
@@ -31,13 +31,6 @@ import eu.etaxonomy.dataportal.DataPortalManager;
 @Deprecated
 public abstract class CdmDataPortalSeleniumRCTestBase extends CdmDataPortalTestBase {
 
-	/**
-	 * @param context
-	 */
-	public CdmDataPortalSeleniumRCTestBase(DataPortalContext context) {
-		super(context);
-	}
-
 	protected static Selenium selenium;
 
 	@Before
diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalTestBase.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalTestBase.java
index 00492d97..ef5708f3 100644
--- a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalTestBase.java
+++ b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/CdmDataPortalTestBase.java
@@ -1,5 +1,5 @@
 /**
- * 
+ *
  */
 package eu.etaxonomy.dataportal.selenium;
 
@@ -22,7 +22,7 @@ import eu.etaxonomy.dataportal.junit.DataPortalContextSuite;
 
 /**
  * @author a.kohlbecker
- * 
+ *
  */
 @RunWith(DataPortalContextSuite.class)
 public abstract class CdmDataPortalTestBase {
@@ -35,14 +35,15 @@ public abstract class CdmDataPortalTestBase {
 
 	protected static WebDriver driver;
 
-	private final DataPortalContext context;
+	private DataPortalContext context;
 
 	public DataPortalContext getContext() {
 		return context;
 	}
 
-	public CdmDataPortalTestBase(DataPortalContext context){
+	public void setContext(DataPortalContext context) {
 		this.context = context;
+
 	}
 
 	@BeforeClass
@@ -88,9 +89,9 @@ public abstract class CdmDataPortalTestBase {
 
 	/**
 	 * -Dwebdriver.firefox.bin=/usr/lib/iceweasel/firefox-bin
-	 * 
+	 *
 	 * See http://code.google.com/p/selenium/wiki/FirefoxDriverInternals
-	 * 
+	 *
 	 * @return
 	 */
 	public static WebDriver initFirefoxDriver() {
@@ -122,7 +123,7 @@ public abstract class CdmDataPortalTestBase {
 	/**
 	 * Return the {@link DataPortalContext#getBaseUri()} of the currently active
 	 * context as String
-	 * 
+	 *
 	 * @return string representatoin of the DataPortal base URI
 	 */
 	public String getBaseUrl() {
diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/ExampleTest.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/ExampleTest.java
index aec81c9f..a6c1ec62 100644
--- a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/ExampleTest.java
+++ b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/ExampleTest.java
@@ -1,9 +1,9 @@
 // $Id$
 /**
  * Copyright (C) 2009 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -11,7 +11,6 @@ package eu.etaxonomy.dataportal.selenium;
 
 import junit.framework.Assert;
 
-import org.junit.Ignore;
 import org.junit.Test;
 import org.openqa.selenium.By;
 import org.openqa.selenium.RenderedWebElement;
@@ -24,13 +23,6 @@ import eu.etaxonomy.dataportal.DataPortalContexts;
 @DataPortalContexts( { DataPortalContext.cichorieae })
 public class ExampleTest extends CdmDataPortalSeleniumRCTestBase {
 
-	/**
-	 * @param context
-	 */
-	public ExampleTest(DataPortalContext context) {
-		super(context);
-	}
-
 	@Test
 	public void testSearchLCommunis() throws Exception {
 		driver.get(getBaseUrl()
@@ -58,7 +50,7 @@ public class ExampleTest extends CdmDataPortalSeleniumRCTestBase {
 
 	/**
 	 * This test emulates the Selenium RC API
-	 * 
+	 *
 	 * @throws Exception
 	 */
 	@Test
diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CichorieaeSearchTest.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CichorieaeSearchTest.java
index 04bbd300..dc56c9c8 100644
--- a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CichorieaeSearchTest.java
+++ b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CichorieaeSearchTest.java
@@ -1,9 +1,9 @@
 // $Id$
 /**
  * Copyright (C) 2009 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -23,11 +23,6 @@ import eu.etaxonomy.dataportal.selenium.CdmDataPortalTestBase;
 @DataPortalContexts( { DataPortalContext.cichorieae })
 public class CichorieaeSearchTest extends CdmDataPortalTestBase {
 
-
-	public CichorieaeSearchTest(DataPortalContext context) {
-		super(context);
-	}
-
 	@Test
 	public void testSearchLCommunis() throws Exception {
 		driver.get(getBaseUrl()
diff --git a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CyprusSearchTest.java b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CyprusSearchTest.java
index c2a750d9..5604c5d4 100644
--- a/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CyprusSearchTest.java
+++ b/modules/cdm_dataportal/test/java/dataportal-selenium-tests/src/test/java/eu/etaxonomy/dataportal/selenium/tests/CyprusSearchTest.java
@@ -1,9 +1,9 @@
 // $Id$
 /**
  * Copyright (C) 2009 EDIT
- * European Distributed Institute of Taxonomy 
+ * European Distributed Institute of Taxonomy
  * http://www.e-taxonomy.eu
- * 
+ *
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
@@ -26,13 +26,6 @@ import eu.etaxonomy.dataportal.selenium.CdmDataPortalTestBase;
 
 @DataPortalContexts( { DataPortalContext.cyprus })
 public class CyprusSearchTest extends CdmDataPortalTestBase{
-	
-	/**
-	 * @param context
-	 */
-	public CyprusSearchTest(DataPortalContext context) {
-		super(context);
-	}
 
 	/**
 	 * see http://dev.e-taxonomy.eu/trac/ticket/2350
