Permalink
Browse files

- Added Guice

- Better build
  • Loading branch information...
1 parent 090281a commit 0340c602ac1a8a50242bbc86fa5309575520f81b cbeust committed Mar 3, 2010
View
BIN 3rdparty/guice-2.0.jar
Binary file not shown.
View
3 build.properties
@@ -1,7 +1,7 @@
root.dir=${basedir}
build.dir=${root.dir}/build
-build.3rdparty.dir=${build.dir}/3rdparty
+build.3rdparty.dir=${root.dir}/build3rdparty
build.maven-bundle.dir=${build.dir}/maven-bundle
#classes=${build.dir}
@@ -14,6 +14,7 @@ example.dir=${basedir}/examples
# Jar files
#
beanshell.jar=bsh-2.0b4.jar
+guice.jar=guice-2.0.jar
#
# Names of distributions
View
25 build.xml
@@ -87,6 +87,7 @@
<fileset dir="${lib.dir}">
<include name="junit.jar" />
<include name="${beanshell.jar}" />
+ <include name="${guice.jar}" />
</fileset>
</path>
@@ -124,7 +125,7 @@
<target name="javadocs">
<javadoc additionalparam="-quiet" destdir="javadocs" source="1.5" windowtitle="TestNG"
- classpath="${testng.jar}:${lib.dir}/ant.jar">
+ classpath="${testng.jar}:${lib.dir}/ant.jar:${guice.jar}">
<fileset dir="${src.dir}" defaultexcludes="yes">
<include name="org/testng/*.java" />
</fileset>
@@ -154,9 +155,13 @@
overwrite="true" />
</target>
- <target name="dist-bsh">
- <antcall target="clean-unjar" />
- <antcall target="extract-beanshell-jar" />
+ <target name="extract-guice-jar">
+ <unjar src="3rdparty/${guice.jar}"
+ dest="${build.3rdparty.dir}"
+ overwrite="true" />
+ </target>
+
+ <target name="dist-bsh" depends="clean-unjar,extract-beanshell-jar,extract-guice-jar" >
<delete file="${testng.jar}" />
<jar destfile="${testng.jar}">
<manifest>
@@ -169,9 +174,9 @@
</jar>
</target>
- <target name="dist-nobsh">
- <antcall target="clean-unjar" />
- <jar destfile="${other.jars.dir}/${testng.nobsh.jar}" update="true">
+ <target name="dist-nobsh" depends="clean-unjar,extract-guice-jar" >
+ <delete file="${other.jars.dir}/${testng.nobsh.jar}" />
+ <jar destfile="${other.jars.dir}/${testng.nobsh.jar}">
<manifest>
<attribute name="Main-Class" value="org.testng.TestNG" />
<attribute name="Implementation-Version" value="${testng.version}-${DSTAMP}${TSTAMP}" />
@@ -203,7 +208,7 @@
excludes="test-output/**,report/**" />
<zipfileset dir="3rdparty"
prefix="${zip.dir}/3rdparty"
- includes="${beanshell.jar},${concurrent.jar}" />
+ includes="${beanshell.jar},${concurrent.jar},${guice.jar}" />
</zip>
</target>
@@ -304,9 +309,9 @@
</target>
<target name="clean">
+ <delete dir="${build.dir}" />
+ <delete dir="${build.maven-bundle.dir}" />
<delete failonerror="false">
- <fileset dir="${build.dir}" includes="**/*" />
- <fileset dir="${build.maven-bundle.dir}" includes="**/*" />
<fileset dir="." includes="*.jar,*.zip" />
</delete>
<ant antfile="test/build.xml" target="clean" />
View
13 src/org/testng/TestNG.java
@@ -1,6 +1,10 @@
package org.testng;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+
import javax.xml.parsers.ParserConfigurationException;
import org.testng.annotations.ITestAnnotation;
@@ -10,6 +14,7 @@
import org.testng.internal.ClassHelper;
import org.testng.internal.IResultListener;
import org.testng.internal.PoolService;
+import org.testng.internal.TestNGGuiceModule;
import org.testng.internal.Utils;
import org.testng.internal.annotations.DefaultAnnotationTransformer;
import org.testng.internal.annotations.IAnnotationFinder;
@@ -688,6 +693,8 @@ public void addInvokedMethodListener(IInvokedMethodListener listener) {
private IMethodInterceptor m_methodInterceptor = null;
+ private Module m_module;
+
/**
* Sets the level of verbosity. This value will override the value specified
* in the test suites.
@@ -751,9 +758,9 @@ private void initializeListeners() {
}
private void initializeAnnotationFinders() {
- if (!VersionInfo.IS_JDK14) {
- m_jdkAnnotationFinder= ClassHelper.createJdkAnnotationFinder(getAnnotationTransformer());
- }
+ m_module = new TestNGGuiceModule(getAnnotationTransformer(), m_objectFactory);
+ Injector injector = Guice.createInjector(m_module);
+ m_jdkAnnotationFinder = injector.getInstance(IAnnotationFinder.class);
}
/**
View
19 src/org/testng/internal/DefaultGuiceModule.java
@@ -0,0 +1,19 @@
+package org.testng.internal;
+
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.Singleton;
+
+import org.testng.IAnnotationTransformer;
+import org.testng.internal.annotations.DefaultAnnotationTransformer;
+import org.testng.internal.annotations.IAnnotationFinder;
+import org.testng.internal.annotations.JDK15AnnotationFinder;
+
+public class DefaultGuiceModule implements Module {
+
+ public void configure(Binder binder) {
+ binder.bind(IAnnotationFinder.class).to(JDK15AnnotationFinder.class).in(Singleton.class);
+ binder.bind(IAnnotationTransformer.class).to(DefaultAnnotationTransformer.class)
+ .in(Singleton.class);
+ }
+}
View
36 src/org/testng/internal/TestNGGuiceModule.java
@@ -0,0 +1,36 @@
+package org.testng.internal;
+
+import com.google.inject.Binder;
+import com.google.inject.Module;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
+
+import org.testng.IAnnotationTransformer;
+import org.testng.IObjectFactory;
+import org.testng.internal.annotations.IAnnotationFinder;
+import org.testng.internal.annotations.JDK15AnnotationFinder;
+
+public class TestNGGuiceModule implements Module {
+
+ private IAnnotationTransformer m_annotationTransformer;
+ private IObjectFactory m_objectFactory;
+
+ public TestNGGuiceModule(IAnnotationTransformer transformer, IObjectFactory factory) {
+ m_annotationTransformer = transformer;
+ m_objectFactory = factory;
+ }
+
+ public void configure(Binder binder) {
+ binder.bind(IAnnotationFinder.class).to(JDK15AnnotationFinder.class).in(Singleton.class);
+ }
+
+ @Provides
+ IAnnotationTransformer provideAnnotationTransformer() {
+ return m_annotationTransformer;
+ }
+
+ @Provides
+ IObjectFactory provideObjectFactory() {
+ return m_objectFactory;
+ }
+}
View
7 src/org/testng/internal/annotations/JDK15AnnotationFinder.java
@@ -1,5 +1,7 @@
package org.testng.internal.annotations;
+import com.google.inject.Inject;
+
import org.testng.IAnnotationTransformer;
import org.testng.IAnnotationTransformer2;
import org.testng.annotations.AfterClass;
@@ -45,12 +47,11 @@
public class JDK15AnnotationFinder implements IAnnotationFinder {
private JDK15TagFactory m_tagFactory = new JDK15TagFactory();
private Map<Class<?>, Class<?>> m_annotationMap = Maps.newHashMap();
+ @Inject
private IAnnotationTransformer m_transformer = null;
@SuppressWarnings({"deprecation"})
- public JDK15AnnotationFinder(IAnnotationTransformer transformer) {
- m_transformer = transformer;
-
+ public JDK15AnnotationFinder() {
m_annotationMap.put(IConfigurationAnnotation.class, Configuration.class);
m_annotationMap.put(IDataProviderAnnotation.class, DataProvider.class);
m_annotationMap.put(IExpectedExceptionsAnnotation.class, ExpectedExceptions.class);
View
5 test/build.xml
@@ -16,11 +16,14 @@
<!-- Compile -->
<!-- ==================================================================== -->
<path id="compile.cp">
+ <pathelement location="${testng.jar}" />
<pathelement location="${build.dir}"/>
<fileset dir="${lib.dir}">
<include name="junit.jar"/>
+<!--
<include name="${beanshell.jar}"/>
- <include name="${qdox.jar}"/>
+ <include name="${guice.jar}"/>
+-->
</fileset>
</path>
View
16 test/src/test/BaseTest.java
@@ -1,7 +1,10 @@
package test;
-import org.testng.IAnnotationTransformer;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
+
import org.testng.IInvokedMethodListener;
import org.testng.ISuite;
import org.testng.ITestResult;
@@ -10,9 +13,8 @@
import org.testng.TestListenerAdapter;
import org.testng.TestRunner;
import org.testng.annotations.BeforeMethod;
-import org.testng.internal.annotations.DefaultAnnotationTransformer;
+import org.testng.internal.DefaultGuiceModule;
import org.testng.internal.annotations.IAnnotationFinder;
-import org.testng.internal.annotations.JDK15AnnotationFinder;
import org.testng.reporters.JUnitXMLReporter;
import org.testng.reporters.TestHTMLReporter;
import org.testng.xml.XmlClass;
@@ -48,12 +50,12 @@
private XmlSuite m_suite= null;
private ITestRunnerFactory m_testRunnerFactory;
- private IAnnotationTransformer m_defaultAnnotationTransformer= new DefaultAnnotationTransformer();
- private IAnnotationFinder m_jdkAnnotationFinder;
+ private Injector m_injector;
public BaseTest() {
m_testRunnerFactory= new InternalTestRunnerFactory(this);
- m_jdkAnnotationFinder= new JDK15AnnotationFinder(m_defaultAnnotationTransformer);
+ Module module = new DefaultGuiceModule();
+ m_injector = Guice.createInjector(module);
}
protected void setDebug() {
@@ -183,7 +185,7 @@ protected void run() {
SuiteRunner suite= new SuiteRunner(m_suite,
m_outputDirectory,
m_testRunnerFactory,
- m_jdkAnnotationFinder);
+ m_injector.getInstance(IAnnotationFinder.class));
suite.run();
}
View
15 test/src/test/mannotation/MAnnotation2SampleTest.java
@@ -1,21 +1,28 @@
package test.mannotation;
-import java.lang.reflect.Method;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
import org.testng.Assert;
import org.testng.annotations.Configuration;
import org.testng.annotations.IConfigurationAnnotation;
import org.testng.annotations.ITestAnnotation;
import org.testng.annotations.Test;
-import org.testng.internal.annotations.DefaultAnnotationTransformer;
+import org.testng.internal.DefaultGuiceModule;
+import org.testng.internal.annotations.IAnnotationFinder;
import org.testng.internal.annotations.JDK15AnnotationFinder;
+import java.lang.reflect.Method;
+
public class MAnnotation2SampleTest {
- private JDK15AnnotationFinder m_finder;
+ private IAnnotationFinder m_finder;
@Configuration(beforeTestClass = true, enabled = true, groups="current")
public void init() {
- m_finder = new JDK15AnnotationFinder(new DefaultAnnotationTransformer());
+ Module module = new DefaultGuiceModule();
+ Injector injector = Guice.createInjector(module);
+ m_finder = injector.getInstance(IAnnotationFinder.class);
}
@Test
View
21 test/src/test/mannotation/MAnnotationSampleTest.java
@@ -1,7 +1,8 @@
package test.mannotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.Module;
import org.testng.Assert;
import org.testng.annotations.Configuration;
@@ -12,18 +13,24 @@
import org.testng.annotations.IParametersAnnotation;
import org.testng.annotations.ITestAnnotation;
import org.testng.annotations.Test;
-import org.testng.internal.annotations.DefaultAnnotationTransformer;
+import org.testng.internal.DefaultGuiceModule;
import org.testng.internal.annotations.IAfterSuite;
+import org.testng.internal.annotations.IAnnotationFinder;
import org.testng.internal.annotations.IBeforeSuite;
import org.testng.internal.annotations.JDK15AnnotationFinder;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+
@Test(enabled = true)
public class MAnnotationSampleTest {
- private JDK15AnnotationFinder m_finder;
+ private IAnnotationFinder m_finder;
@Configuration(beforeTestClass = true, enabled = true)
public void init() {
- m_finder = new JDK15AnnotationFinder(new DefaultAnnotationTransformer());
+ Module module = new DefaultGuiceModule();
+ Injector injector = Guice.createInjector(module);
+ m_finder = injector.getInstance(IAnnotationFinder.class);
}
public void verifyTestClassLevel() {
@@ -210,7 +217,9 @@ public void verifyFactory() throws SecurityException, NoSuchMethodException
public void verifyParameters() throws SecurityException, NoSuchMethodException
{
- m_finder = new JDK15AnnotationFinder(new DefaultAnnotationTransformer());
+ Module module = new DefaultGuiceModule();
+ Injector injector = Guice.createInjector(module);
+ m_finder = injector.getInstance(IAnnotationFinder.class);
Method method = MTest1.class.getMethod("parameters", new Class[0]);
IParametersAnnotation parameters =
(IParametersAnnotation) m_finder.findAnnotation(method, IParametersAnnotation.class);
View
4 test/testng-single.xml
@@ -24,8 +24,10 @@
</groups>
-->
<classes>
- <class name="test.regression.MyTestngTest2"/>
+ <class name="test.dataprovider.FailedDataProviderTest" />
<!--
+ <class name="test.tmp.B"/>
+ <class name="test.regression.MyTestngTest2"/>
<class name="test.regression.BeforeTestFailingTest"/>
<class name="test.inject.InjectDataProviderTest"/>
<class name="test.dataprovider.IteratorParallelTest"/>

0 comments on commit 0340c60

Please sign in to comment.