Package org.apache.onami.test.reflection

Examples of org.apache.onami.test.reflection.HandleException


                                  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 ( MoreTypes.getRawType( new TypeLiteral<Iterable<Module>>()
            {
            }.getType() ).isAssignableFrom( returnType ) )
            {
                addModules( (Iterable<Module>) method.invoke( type ) );
            }
            else if ( MoreTypes.getRawType( new TypeLiteral<Module[]>()
            {
            }.getType() ).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 );
        }
    }
View Full Code Here


            {
                modules.add( module.newInstance() );
            }
            catch ( Exception e )
            {
                throw new HandleException( e );
            }
        }
    }
View Full Code Here

            {
                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() );
            }
        }
View Full Code Here

                {
                    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 );
    }
View Full Code Here

    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 ) )
        {
View Full Code Here

TOP

Related Classes of org.apache.onami.test.reflection.HandleException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.