http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/GuiceProvidedModules.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/GuiceProvidedModules.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/GuiceProvidedModules.java deleted file mode 100644 index 1213142..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/GuiceProvidedModules.java +++ /dev/null @@ -1,43 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * <p> - * Annotate a <b>public static</b> method to create a Google Guice {@link com.google.inject.Module} provider. - * </p> - * <p> - * The method return type must be one of: - * <ul> - * <li>com.google.inject.Module</li> - * <li>Iterable<com.google.inject.Module></li> - * <li>com.google.inject.Module[]</li> - * </p> - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface GuiceProvidedModules { - -}
http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/Mock.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/Mock.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/Mock.java deleted file mode 100644 index d2e32fa..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/Mock.java +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.annotation; - -import java.lang.annotation.Annotation; -import java.lang.annotation.ElementType; -import java.lang.annotation.Inherited; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotate your filed into which {@link org.apache.onami.test.GuiceMockModule} will create and inject the mock object. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -@Inherited -public @interface Mock { - - /** - * Annotation class used to mark that no annotation binding is defined. - */ - public static @interface NoAnnotation { - } - - /** - * Indicates if this mock object has to be resetted after each test method Default: true - */ - boolean resetAfter() default true; - - /** - * The name of the method that provides to mock creation. - */ - String providedBy() default ""; - - /** - * The {@link Class} that contains the method {@link Mock#providedBy()}. By default: the filed declaring class. - */ - Class<?> providerClass() default Object.class; - - /** - * Specifies an annotation {@link Class} that will be used in the <em>Google Guice</em> binder to execute the literal - * annotating binding. - */ - Class<? extends Annotation> annotatedWith() default NoAnnotation.class; - - /** - * Specifies an {@link String} annotation that will be used in the <em>Google Guice</em> binder to execute the - * literal annotating binding via {@link com.google.inject.name.Named} class. - */ - String namedWith() default ""; - - /** - * Specifies TODO - */ - MockObjType type() default MockObjType.DEFAULT; - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockFramework.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockFramework.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockFramework.java deleted file mode 100644 index 3e057f7..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockFramework.java +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Annotate test class to specify you favorite mock framework. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface MockFramework { - - /** - * Type of mock that JUnice has to create. - */ - MockType value(); - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockObjType.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockObjType.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockObjType.java deleted file mode 100644 index ce684b1..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockObjType.java +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.annotation; - -/** - * Enumeration class to specifies the preferred mock object. - */ -public enum MockObjType { - - /** - * @see EasyMock.createMock - */ - EASY_MOCK_NORMAL, - - /** - * @see EasyMock.createStrictMock - */ - EASY_MOCK_STRICT, - - /** - * @see EasyMock.createNiceMock - */ - EASY_MOCK_NICE, - - /** - * Use default mock creation mode - */ - DEFAULT - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockType.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockType.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockType.java deleted file mode 100644 index 1082464..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/annotation/MockType.java +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.annotation; - -/** - * Enumeration class to specifies your preferred mock framework. - * - * @see MockFramework - */ -public enum MockType { - /** - * Identify the Easy Mock framework - */ - EASY_MOCK, - - /** - * Identify the Mockito framework - */ - MOCKITO - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/guice/MockMembersInjector.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/guice/MockMembersInjector.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/guice/MockMembersInjector.java deleted file mode 100644 index 6ce31ac..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/guice/MockMembersInjector.java +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.guice; - -import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.Map; - -import com.google.inject.MembersInjector; - -/** - * Class to inject via google-guice mock members into test cases classes. - * - * @param <T> type to inject members of - */ -public class MockMembersInjector<T> implements MembersInjector<T> { - - private final Field field; - - private final Map<Field, Object> mockedObjects; - - /** - * Create a new instance. - * - * @param field the field that has to be injected. - * @param mockedObjects the map of mocked object. - */ - public MockMembersInjector(final Field field, Map<Field, Object> mockedObjects) { - this.field = field; - this.mockedObjects = mockedObjects; - AccessController.doPrivileged(new PrivilegedAction<Void>() { - - public Void run() { - field.setAccessible(true); - return null; - } - - }); - } - - /** - * {@inheritDoc} - */ - public void injectMembers(T t) { - try { - field.set(t, mockedObjects.get(field)); - } catch (IllegalAccessException e) { - throw new RuntimeException(e); - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/guice/MockTypeListener.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/guice/MockTypeListener.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/guice/MockTypeListener.java deleted file mode 100644 index 1a6964e..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/guice/MockTypeListener.java +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.guice; - -import java.lang.reflect.Field; -import java.util.Map; - -import org.apache.james.mpt.onami.test.annotation.Mock; -import org.apache.james.mpt.onami.test.reflection.AnnotationHandler; -import org.apache.james.mpt.onami.test.reflection.ClassVisitor; -import org.apache.james.mpt.onami.test.reflection.HandleException; - -import com.google.inject.TypeLiteral; -import com.google.inject.spi.TypeEncounter; -import com.google.inject.spi.TypeListener; - -/** - * <p> - * {@link TypeListener} implementation. - * </p> - * <p> - * Creates a specific {@link MockMembersInjector} for each {@link Mock} annotation found. - * </p> - * - * @see MockMembersInjector - * @see Mock - */ -public class MockTypeListener implements TypeListener { - - private final Map<Field, Object> mockedObjects; - - /** - * Creates a new {@code MockTypeListener} instance given a map of mocked objects. - * - * @param mockedObjects a map of mocked objects - */ - public MockTypeListener(Map<Field, Object> mockedObjects) { - this.mockedObjects = mockedObjects; - } - - /** - * {@inheritDoc} - */ - public <I> void hear(final TypeLiteral<I> typeLiteral, final TypeEncounter<I> typeEncounter) { - try { - new ClassVisitor() - .registerHandler(Mock.class, new AnnotationHandler<Mock, Field>() { - - public void handle(Mock annotation, Field field) - throws HandleException { - typeEncounter.register(new MockMembersInjector<I>(field, mockedObjects)); - } - - }) - .visit(typeLiteral.getRawType()); - } catch (HandleException e) { - typeEncounter.addError(e); - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceInjectableClassHandler.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceInjectableClassHandler.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceInjectableClassHandler.java deleted file mode 100644 index 3cc27f7..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceInjectableClassHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.handler; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.Member; -import java.util.HashSet; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.james.mpt.onami.test.reflection.AnnotationHandler; -import org.apache.james.mpt.onami.test.reflection.HandleException; - -/** - * Handler class to handle all {@link com.google.inject.Inject} and {@link javax.inject.Inject} annotations. - * - * @param <A> whatever annotation type - * @see org.apache.onami.test.reflection.ClassVisitor - */ -public final class GuiceInjectableClassHandler<A extends Annotation> implements AnnotationHandler<A, AccessibleObject> { - - private static final Logger LOGGER = Logger.getLogger(GuiceInjectableClassHandler.class.getName()); - - /** - * Contains the guice injectable classes founded, after inspection. - */ - protected final Set<Class<?>> classes = new HashSet<Class<?>>(); - - /** - * Return all {@link Class} that contains at last one {@link com.google.inject.Inject} or - * {@link javax.inject.Inject} annotation. - * - * @return {@link Class} array. - */ - public Class<?>[] getClasses() { - return classes.toArray(new Class<?>[classes.size()]); - } - - /** - * {@inheritDoc} - */ - public void handle(A annotation, AccessibleObject element) - throws HandleException { - Class<?> type = null; - - if (element instanceof Member) { - type = ((Member) element).getDeclaringClass(); - } - - if (type != null && !classes.contains(type)) { - if (LOGGER.isLoggable(Level.FINER)) { - LOGGER.finer(" Found injectable type: " + type); - } - classes.add(type); - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceModuleHandler.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceModuleHandler.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceModuleHandler.java deleted file mode 100644 index 3181157..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceModuleHandler.java +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.handler; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.james.mpt.onami.test.annotation.GuiceModules; -import org.apache.james.mpt.onami.test.reflection.ClassHandler; -import org.apache.james.mpt.onami.test.reflection.HandleException; - -import com.google.inject.Module; - -/** - * Handler class to handle all {@link GuiceModules} annotations. - * - * @see org.apache.onami.test.reflection.ClassVisitor - */ -public final class GuiceModuleHandler implements ClassHandler<GuiceModules> { - - private static final Logger LOGGER = Logger.getLogger(GuiceModuleHandler.class.getName()); - - private final List<Module> modules = new ArrayList<Module>(); - - /** - * @return the modules - */ - public List<Module> getModules() { - return modules; - } - - /** - * {@inheritDoc} - */ - public void handle(GuiceModules annotation, Class<?> element) - throws HandleException { - for (Class<? extends Module> module : annotation.value()) { - if (LOGGER.isLoggable(Level.FINER)) { - LOGGER.finer(" Try to create module: " + module); - } - try { - modules.add(module.newInstance()); - } catch (Exception e) { - throw new HandleException(e); - } - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceProvidedModuleHandler.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceProvidedModuleHandler.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceProvidedModuleHandler.java deleted file mode 100644 index ed9ed7b..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/GuiceProvidedModuleHandler.java +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.handler; - -import static java.lang.String.format; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.james.mpt.onami.test.annotation.GuiceProvidedModules; -import org.apache.james.mpt.onami.test.reflection.HandleException; -import org.apache.james.mpt.onami.test.reflection.MethodHandler; - -import com.google.inject.Module; -import com.google.inject.TypeLiteral; - -/** - * Handler class to handle all {@link GuiceProvidedModules} annotations. - * - * @see org.apache.onami.test.reflection.ClassVisitor - * @see GuiceProvidedModules - */ -public final class GuiceProvidedModuleHandler implements MethodHandler<GuiceProvidedModules> { - - private static final Logger LOGGER = Logger.getLogger(GuiceProvidedModuleHandler.class.getName()); - - private final List<Module> modules = new ArrayList<Module>(); - - /** - * @return the guiceProviderModuleRegistry - */ - public List<Module> getModules() { - return modules; - } - - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - public void handle(GuiceProvidedModules annotation, Method method) - throws HandleException { - final Class<?> returnType = method.getReturnType(); - - if (LOGGER.isLoggable(Level.FINER)) { - LOGGER.finer(format(" Found %s annotated method, checking if return type '%s' is one of ( %s | Iterable<%s> | %s[] )", - GuiceProvidedModules.class.getSimpleName(), - returnType.getName(), - Module.class.getName(), - Module.class.getName(), - Module.class.getName())); - } - - if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isStatic(method.getModifiers())) { - throw new HandleException("Impossible to invoke method: " + method + ", it has to be static and public"); - } - - final Class<?> type = method.getDeclaringClass(); - - try { - if (Module.class.isAssignableFrom(returnType)) { - modules.add((Module) method.invoke(type)); - } else if (new TypeLiteral<Iterable<Module>>() { - }.getRawType().isAssignableFrom(returnType)) { - addModules((Iterable<Module>) method.invoke(type)); - } else if (new TypeLiteral<Module[]>() { - }.getRawType().isAssignableFrom(returnType)) { - addModules((Module[]) method.invoke(type)); - } else { - throw new ClassCastException(format(" Incompatible return type: %s.\nThe return type must be one of ( %s | Iterable<%s> | %s[] )", - returnType.getName(), - Module.class.getName(), - Module.class.getName(), - Module.class.getName())); - } - - if (LOGGER.isLoggable(Level.FINER)) { - LOGGER.finer(" Invoked method: " + method.toGenericString()); - } - } catch (Exception e) { - throw new HandleException(e); - } - } - - private void addModules(Iterable<Module> modules) { - for (Module module : modules) { - this.modules.add(module); - } - } - - private void addModules(Module... modules) { - Collections.addAll(this.modules, modules); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/MockFrameworkHandler.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/MockFrameworkHandler.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/MockFrameworkHandler.java deleted file mode 100644 index e6b4433..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/MockFrameworkHandler.java +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.handler; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.james.mpt.onami.test.annotation.MockFramework; -import org.apache.james.mpt.onami.test.annotation.MockType; -import org.apache.james.mpt.onami.test.reflection.ClassHandler; -import org.apache.james.mpt.onami.test.reflection.HandleException; - -/** - * Handler class to handle all {@link MockFramework} annotations. - * - * @see org.apache.onami.test.reflection.ClassVisitor - * @see MockFramework - */ -public final class MockFrameworkHandler implements ClassHandler<MockFramework> { - - private static final Logger LOGGER = Logger.getLogger(MockFrameworkHandler.class.getName()); - - private MockType mockType; - - /** - * @return the mockType - */ - public MockType getMockType() { - return mockType; - } - - /** - * {@inheritDoc} - */ - public void handle(MockFramework annotation, Class<?> element) - throws HandleException { - if (mockType != null && mockType != annotation.value()) { - throw new HandleException("Inconsistent mock framework found. " + "Mock framework already set [set: " - + mockType + " now found: " + annotation.value() + "]"); - } - - if (LOGGER.isLoggable(Level.FINER)) { - LOGGER.finer(" Found MockFramework: " + annotation.value()); - } - - mockType = annotation.value(); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/MockHandler.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/MockHandler.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/MockHandler.java deleted file mode 100644 index 5b68144..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/handler/MockHandler.java +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.handler; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.james.mpt.onami.test.annotation.Mock; -import org.apache.james.mpt.onami.test.mock.MockEngine; -import org.apache.james.mpt.onami.test.reflection.FieldHandler; -import org.apache.james.mpt.onami.test.reflection.HandleException; - - -/** - * Handler class to handle all {@link Mock} annotations. - * - * @see org.apache.onami.test.reflection.ClassVisitor - * @see Mock - */ -public final class MockHandler implements FieldHandler<Mock> { - - private static final Logger LOGGER = Logger.getLogger(MockHandler.class.getName()); - - private final HashMap<Field, Object> mockedObjects = new HashMap<Field, Object>(1); - - /** - * Return the mocked objects. - * - * @param engine the {@link MockEngine} - * @return the map of mocked objects - */ - public HashMap<Field, Object> getMockedObject(MockEngine engine) { - createMockedObjectBymockFramekork(engine); - return mockedObjects; - } - - private void createMockedObjectBymockFramekork(MockEngine engine) { - for (Entry<Field, Object> entry : mockedObjects.entrySet()) { - if (entry.getValue() instanceof Class<?>) { - Field field = entry.getKey(); - Mock mock = field.getAnnotation(Mock.class); - mockedObjects.put(entry.getKey(), engine.createMock((Class<?>) entry.getValue(), mock.type())); - } - } - } - - - /** - * Invoked when the visitor founds an element with a {@link Mock} annotation. - * - * @param annotation The {@link Mock} annotation type - * @param element the {@link Mock} annotated fiels - * @throws HandleException when an error occurs. - */ - @SuppressWarnings("unchecked") - public void handle(final Mock annotation, final Field element) - throws HandleException { - final Class<? super Object> type = (Class<? super Object>) element.getDeclaringClass(); - - if (LOGGER.isLoggable(Level.FINER)) { - LOGGER.finer(" Found annotated field: " + element); - } - if (annotation.providedBy().length() > 0) { - Class<?> providedClass = type; - if (annotation.providerClass() != Object.class) { - providedClass = annotation.providerClass(); - } - try { - Method method = providedClass.getMethod(annotation.providedBy()); - - if (!element.getType().isAssignableFrom(method.getReturnType())) { - throw new HandleException("Impossible to mock %s due to compatibility type, method provider %s#%s returns %s", - element.getDeclaringClass().getName(), - providedClass.getName(), - annotation.providedBy(), - method.getReturnType().getName()); - } - try { - Object mocked = getMockProviderForType(element.getType(), method, type); - mockedObjects.put(element, mocked); - } catch (Throwable t) { - throw new HandleException("Impossible to mock %s, method provider %s#%s raised an error: %s", - element.getDeclaringClass().getName(), - providedClass.getName(), - annotation.providedBy(), - t); - } - } catch (SecurityException e) { - throw new HandleException("Impossible to mock %s, impossible to access to method provider %s#%s: %s", - element.getDeclaringClass().getName(), - providedClass.getName(), - annotation.providedBy(), - e); - } catch (NoSuchMethodException e) { - throw new HandleException("Impossible to mock %s, the method provider %s#%s doesn't exist.", - element.getDeclaringClass().getName(), - providedClass.getName(), - annotation.providedBy()); - } - } else { - mockedObjects.put(element, element.getType()); - } - } - - @SuppressWarnings("unchecked") - private <T> T getMockProviderForType(T t, Method method, Class<?> cls) - throws HandleException { - if (method.getReturnType() == t) { - try { - if (LOGGER.isLoggable(Level.FINER)) { - LOGGER.finer(" ...invoke Provider method for Mock: " + method.getName()); - } - if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isStatic(method.getModifiers())) { - throw new HandleException("Impossible to invoke method %s#%s. The method shuld be 'static public %s %s()", - cls.getName(), - method.getName(), - method.getReturnType().getName(), - method.getName()); - } - - return (T) method.invoke(cls); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - throw new HandleException("The method: %s should return type %s", method, t); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/MockEngine.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/MockEngine.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/MockEngine.java deleted file mode 100644 index c8b5f15..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/MockEngine.java +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.mock; - -import org.apache.james.mpt.onami.test.annotation.MockObjType; - -/** - * Interface to specify mock framework class engine. - * - * @see org.apache.onami.test.mock.framework.EasyMockFramework - * @see org.apache.onami.test.mock.framework.MockitoFramework - */ -public interface MockEngine { - - /** - * Reset the mock objects - * - * @param objects to reset. - */ - void resetMock(Object... objects); - - /** - * Create a typed mock - * - * @param <T> Class to mock - * @param cls Class to mock - * @param type the {@link MockObjType} - * @return the mock object - */ - <T> T createMock(Class<T> cls, MockObjType type); - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/framework/EasyMockFramework.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/framework/EasyMockFramework.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/framework/EasyMockFramework.java deleted file mode 100644 index 9bd55d8..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/framework/EasyMockFramework.java +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.mock.framework; - -import org.apache.james.mpt.onami.test.annotation.MockObjType; -import org.apache.james.mpt.onami.test.mock.MockEngine; -import org.easymock.EasyMock; - -/** - * Specifies the Easy-Mock Framework. - * - * @see MockEngine - */ -public class EasyMockFramework implements MockEngine { - - /** - * {@inheritDoc} - */ - public void resetMock(Object... objects) { - EasyMock.reset(objects); - } - - /** - * {@inheritDoc} - */ - public <T> T createMock(Class<T> cls, MockObjType type) { - switch (type) { - case EASY_MOCK_NICE: - return EasyMock.createNiceMock(cls); - - case EASY_MOCK_STRICT: - return EasyMock.createStrictMock(cls); - - case EASY_MOCK_NORMAL: - case DEFAULT: - return EasyMock.createMock(cls); - - default: - throw new IllegalArgumentException("Unsupported mock type '" + type + "' for Easy-Mock Framework."); - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/framework/MockitoFramework.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/framework/MockitoFramework.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/framework/MockitoFramework.java deleted file mode 100644 index 5e6c5cb..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/mock/framework/MockitoFramework.java +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.mock.framework; - -import static com.google.common.base.Preconditions.checkArgument; -import static org.apache.james.mpt.onami.test.annotation.MockObjType.DEFAULT; - -import org.apache.james.mpt.onami.test.annotation.MockObjType; -import org.apache.james.mpt.onami.test.mock.MockEngine; -import org.mockito.Mockito; - -/** - * Specifies the Mockito Framework. - * - * @see MockEngine - */ -public class MockitoFramework - implements MockEngine { - - /** - * {@inheritDoc} - */ - public void resetMock(Object... objects) { - Mockito.reset(objects); - } - - /** - * {@inheritDoc} - */ - public <T> T createMock(Class<T> cls, MockObjType type) { - checkArgument(DEFAULT == type, "Unsupported mock type '%s' for Mockito Framework.", type); - return Mockito.mock(cls); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/AnnotationHandler.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/AnnotationHandler.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/AnnotationHandler.java deleted file mode 100644 index 3ae233f..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/AnnotationHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.reflection; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; - -/** - * Interface to specify a generic annotation handler. - * - * @param <A> whatever annotation type - * @param <E> the element annotated with an annotation type - */ -public interface AnnotationHandler<A extends Annotation, E extends AnnotatedElement> { - - /** - * Invoked when {@link ClassVisitor} found an annotation into a class. - * - * @param annotation handled annotation - * @param element the element annotated with input annotation - * @throws HandleException if an error occurs while processing the annotated element - * and the related annotation - */ - void handle(A annotation, E element) - throws HandleException; - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/ClassHandler.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/ClassHandler.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/ClassHandler.java deleted file mode 100644 index 23eacb5..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/ClassHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.reflection; - -import java.lang.annotation.Annotation; - -/** - * Interface to specify a generic class handler. - * - * @param <A> whatever annotation type - */ -public interface ClassHandler<A extends Annotation> extends AnnotationHandler<A, Class<?>> { - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/ClassVisitor.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/ClassVisitor.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/ClassVisitor.java deleted file mode 100644 index a28e1ef..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/ClassVisitor.java +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.reflection; - -import static com.google.common.base.Preconditions.checkArgument; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.util.logging.Level; -import java.util.logging.Logger; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; - -/** - * <p> - * Class visitor engine. - * </p> - * <p> - * Visit the input class and all super classes and invokes handler to register annotations. - * </p> - */ -public final class ClassVisitor { - - private static final String JAVA_PACKAGE = "java"; - - private static final Logger LOGGER = Logger.getLogger(ClassVisitor.class.getName()); - - private final Multimap<Class<? extends Annotation>, AnnotationHandler<? extends Annotation, ? extends AnnotatedElement>> handlers = - ArrayListMultimap.create(); - - /** - * Registers an annotation handler. - * - * @param <A> whatever annotation type - * @param annotationType the annotation class to handle - * @param handler the related annotation handler - * @return the current {@code ClassVisitor} instance - */ - public <A extends Annotation> ClassVisitor registerHandler(Class<A> annotationType, - AnnotationHandler<A, ? extends AnnotatedElement> handler) { - handlers.put(annotationType, handler); - return this; - } - - /** - * Visits all fields, methods and super classes of the input class. - * - * @param <T> any type - * @param type The type - * @throws HandleException when an error occurs. - */ - public <T> void visit(final Class<? super T> type) - throws HandleException { - checkArgument(type != null, "Type to be visited cannot be null"); - - if (LOGGER.isLoggable(Level.FINER)) { - LOGGER.finer(" Visit class: " + type); - } - - if (type.getPackage() != null && type.getPackage().getName().startsWith(JAVA_PACKAGE)) { - return; - } - - handle(type); - handle(type.getDeclaredFields()); - handle(type.getDeclaredMethods()); - - visit((Class<? super T>) type.getSuperclass()); - } - - @SuppressWarnings("unchecked") - private void handle(AnnotatedElement... elements) - throws HandleException { - for (AnnotatedElement element : elements) { - for (Annotation annotation : element.getAnnotations()) { - for (AnnotationHandler<? extends Annotation, ? extends AnnotatedElement> handler : handlers.get(annotation.annotationType())) { - ((AnnotationHandler<Annotation, AnnotatedElement>) handler).handle(annotation, element); - } - } - } - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/FieldHandler.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/FieldHandler.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/FieldHandler.java deleted file mode 100644 index 9c98cdc..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/FieldHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.reflection; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Field; - -/** - * Interface to specify a generic field handler. - * - * @param <A> whatever annotation type - */ -public interface FieldHandler<A extends Annotation> extends AnnotationHandler<A, Field> { - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/HandleException.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/HandleException.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/HandleException.java deleted file mode 100644 index 8da8143..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/HandleException.java +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.reflection; - -import static java.lang.String.format; - -/** - * Exception thrown by a {@link ClassVisitor} when a error occurs. - */ -public final class HandleException extends Exception { - - private static final long serialVersionUID = 1L; - - /** - * Constructs a new HandleException with the specified detail message and cause. - * - * @param message detail message - * @param cause the cause - */ - public HandleException(String message, Throwable cause) { - super(message, cause); - } - - /** - * Constructs a new HandleException with the specified detail message. - * - * @param message a format string - * @param args arguments referenced by the format specifiers in the format string - * @see String#format(String, Object...) - */ - public HandleException(String message, Object... args) { - super(format(message, args)); - } - - /** - * Constructs a new HandleException with the specified cause. - * - * @param cause the cause - */ - public HandleException(Throwable cause) { - super(cause); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/MethodHandler.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/MethodHandler.java b/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/MethodHandler.java deleted file mode 100644 index 6f43140..0000000 --- a/mpt/onami-test/src/main/java/org/apache/james/mpt/onami/test/reflection/MethodHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test.reflection; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; - -/** - * Interface to specify a generic method handler. - * - * @param <A> whatever annotation type - */ -public interface MethodHandler<A extends Annotation> extends AnnotationHandler<A, Method> { - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractEmptyTestCase.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractEmptyTestCase.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractEmptyTestCase.java deleted file mode 100644 index b6f090e..0000000 --- a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractEmptyTestCase.java +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test; - -import java.io.File; -import java.io.FileInputStream; -import java.util.logging.LogManager; - -import org.junit.BeforeClass; - -/** - * Utility class. Just for logging initialization. - */ -abstract public class AbstractEmptyTestCase { - - @BeforeClass - public static void initLogging() - throws Exception { - LogManager.getLogManager().readConfiguration(new FileInputStream( - new File( - "src/test/resources/log4j.properties"))); - } -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractMockTestCase.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractMockTestCase.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractMockTestCase.java deleted file mode 100644 index 729a995..0000000 --- a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractMockTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test; - -import org.apache.james.mpt.onami.test.annotation.Mock; -import org.apache.james.mpt.onami.test.data.Service; -import org.easymock.EasyMock; - -abstract public class AbstractMockTestCase extends AbstractEmptyTestCase { - - // Create and inject a Provided EasyMock - @Mock(providedBy = "getMock") - protected Service providedMock; - - public static Service getMock() { - // Create the mock object and inject the dependency via Google-guice into HelloWorld - return EasyMock.createNiceMock(Service.class); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractMockitoTestCase.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractMockitoTestCase.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractMockitoTestCase.java deleted file mode 100644 index a4c0432..0000000 --- a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractMockitoTestCase.java +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test; - - -import org.apache.james.mpt.onami.test.annotation.Mock; -import org.apache.james.mpt.onami.test.annotation.MockFramework; -import org.apache.james.mpt.onami.test.annotation.MockType; -import org.apache.james.mpt.onami.test.data.Service; -import org.mockito.Mockito; - -@MockFramework(MockType.MOCKITO) -abstract public class AbstractMockitoTestCase extends AbstractEmptyTestCase { - - // Create and inject a Provided EasyMock - @Mock(providedBy = "getMock") - protected Service providedMock; - - // @MockProvider - public static Service getMock() { - // Create the mock object and inject the dependency via Google-guice into HelloWorld - return Mockito.mock(Service.class); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractTestCase.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractTestCase.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractTestCase.java deleted file mode 100644 index ec6e0ca..0000000 --- a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/AbstractTestCase.java +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test; - -import java.util.ArrayList; - -import org.apache.james.mpt.onami.test.annotation.GuiceModules; -import org.apache.james.mpt.onami.test.annotation.GuiceProvidedModules; -import org.apache.james.mpt.onami.test.data.SimpleModule; -import org.junit.runner.RunWith; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.name.Names; - -@RunWith(OnamiRunner.class) -@GuiceModules(SimpleModule.class) -abstract public class AbstractTestCase extends AbstractEmptyTestCase { - - @GuiceProvidedModules - public static Module genericModule() { - return new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(Names.named("test.info.inject")).toInstance("JUnice = JUnit + Guice"); - } - }; - } - - @GuiceProvidedModules - public static Iterable<Module> genericModule2() { - AbstractModule a = new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(Names.named("test.info.inject2")).toInstance("JUnice = JUnit + Guice Iterable"); - } - }; - - ArrayList<Module> al = new ArrayList<Module>(); - al.add(a); - return al; - } - - @GuiceProvidedModules - public static Module[] genericModule3() { - AbstractModule a = new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(Names.named("test.info.inject3")).toInstance("JUnice = JUnit + Guice Array"); - } - }; - return new Module[]{a}; - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectDependingMockObjectTestCase.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectDependingMockObjectTestCase.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectDependingMockObjectTestCase.java deleted file mode 100644 index 092c98a..0000000 --- a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectDependingMockObjectTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import org.apache.james.mpt.onami.test.annotation.Mock; -import org.apache.james.mpt.onami.test.data.HelloWorld; -import org.apache.james.mpt.onami.test.data.Service; -import org.easymock.EasyMock; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.google.inject.AbstractModule; -import com.google.inject.Injector; -import com.google.inject.TypeLiteral; - -@RunWith(OnamiRunner.class) -public class InjectDependingMockObjectTestCase { - - @Mock - static private Service service; - - @Inject - Injector injector; - - private HelloWorld helloWorld; - - @Before - public void setUp() { - final List<Service> list = new ArrayList<Service>(); - list.add(service); - - AbstractModule listAbstractModule = new AbstractModule() { - @Override - protected void configure() { - bind(new TypeLiteral<List<Service>>() { - }).toInstance(list); - } - }; - - Injector cInjector = injector.createChildInjector(listAbstractModule); - helloWorld = cInjector.getInstance(HelloWorld.class); - // required for optional dependencies - cInjector.injectMembers(helloWorld); - } - - @Test - public void testMock() { - Assert.assertNotNull(helloWorld); - Assert.assertNotNull(service); - EasyMock.expect(service.go()).andReturn("Ciao"); - EasyMock.expectLastCall().once(); - - EasyMock.replay(service); - helloWorld.sayHalloByServiceLists(); - EasyMock.verify(service); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectFromSuperClassTestCase.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectFromSuperClassTestCase.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectFromSuperClassTestCase.java deleted file mode 100644 index 0561394..0000000 --- a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectFromSuperClassTestCase.java +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test; - -import javax.inject.Inject; - -import org.junit.Assert; -import org.junit.Test; - -import com.google.inject.name.Named; - -public class InjectFromSuperClassTestCase extends AbstractTestCase { - - @Inject - @Named("test.info.inject") - private String info; - - @Inject - @Named("test.info.inject2") - private String infoFromIterable; - - @Inject - @Named("test.info.inject3") - private String infoFromArray; - - @Test - public void testInjectFromSuperClass() { - Assert.assertNotNull(info); - Assert.assertEquals("JUnice = JUnit + Guice", info); - - Assert.assertNotNull(infoFromIterable); - Assert.assertEquals("JUnice = JUnit + Guice Iterable", infoFromIterable); - - Assert.assertNotNull(infoFromArray); - Assert.assertEquals("JUnice = JUnit + Guice Array", infoFromArray); - } - -} http://git-wip-us.apache.org/repos/asf/james-project/blob/78cf06ab/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectJSR330ModuleClassTestCase.java ---------------------------------------------------------------------- diff --git a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectJSR330ModuleClassTestCase.java b/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectJSR330ModuleClassTestCase.java deleted file mode 100644 index 78a98a0..0000000 --- a/mpt/onami-test/src/test/java/org/apache/james/mpt/onami/test/InjectJSR330ModuleClassTestCase.java +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************** - * Licensed to the Apache Software Foundation (ASF) under one * - * or more contributor license agreements. See the NOTICE file * - * distributed with this work for additional information * - * regarding copyright ownership. The ASF licenses this file * - * to you under the Apache License, Version 2.0 (the * - * "License"); you may not use this file except in compliance * - * with the License. You may obtain a copy of the License at * - * * - * http://www.apache.org/licenses/LICENSE-2.0 * - * * - * Unless required by applicable law or agreed to in writing, * - * software distributed under the License is distributed on an * - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * - * KIND, either express or implied. See the License for the * - * specific language governing permissions and limitations * - * under the License. * - ****************************************************************/ - -package org.apache.james.mpt.onami.test; - -import javax.inject.Inject; -import javax.inject.Named; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.google.inject.AbstractModule; -import com.google.inject.name.Names; - -@RunWith(OnamiRunner.class) -public class InjectJSR330ModuleClassTestCase extends AbstractModule { - - @Override - public void configure() { - bind(Integer.class).annotatedWith(Names.named("numeber.version")).toInstance(10); - } - - @Inject - @Named("numeber.version") - private Integer version; - - @Test - public void testInjectModuleClass() { - Assert.assertNotNull(version); - Assert.assertEquals(10, version.intValue()); - } - -} --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org