Examples of TestNGException


Examples of org.testng.TestNGException

                       IAnnotationFinder annotationFinder,
                       ITestContext testContext)
  {
    super(method, annotationFinder);
    if (! instance.getClass().isAssignableFrom(method.getDeclaringClass())) {
      throw new TestNGException("Mismatch between instance/method classes:"
          + instance.getClass() + " " + method.getDeclaringClass());
    }
   
    m_instance = instance;
    m_xmlTest = xmlTest;
View Full Code Here

Examples of org.testng.TestNGException

          if (null != cls) {
            for (Method m : cls.getMethods()) {
              IAnnotation a = annotationFinder.findAnnotation(m, org.testng.internal.annotations.IObjectFactory.class);
              if (null != a) {
                if (!IObjectFactory.class.isAssignableFrom(m.getReturnType())) {
                  throw new TestNGException("Return type of " + m + " is not IObjectFactory");
                }
                try {
                  Object instance = cls.newInstance();
                  instanceMap.put(cls, java.util.Arrays.asList(instance));
                  if (m.getParameterTypes().length > 0 && m.getParameterTypes()[0].equals(ITestContext.class)) {
                    objectFactory = (IObjectFactory) m.invoke(instance, testContext);
                  } else {
                    objectFactory = (IObjectFactory) m.invoke(instance);
                  }
                  break outer;
                }
                catch (Exception ex) {
                  throw new TestNGException("Error creating object factory", ex);
                }
              }
            }
          }
        } catch (NoClassDefFoundError e) {
View Full Code Here

Examples of org.testng.TestNGException

    }
    catch (InstantiationException ex) {
      return ClassHelper.tryOtherConstructor(constructor.getDeclaringClass());
    }
    catch(Exception ex) {
      throw new TestNGException("Cannot instantiate class " + constructor.getDeclaringClass().getName(), ex);
    }
  }
View Full Code Here

Examples of org.testng.TestNGException

          if (null == value) {
            if (optionalValues != null) {
              value = optionalValues[i];
            }
            if (null == value) {
            throw new TestNGException("Parameter '" + p + "' is required by "
                + methodAnnotation
                + " on method "
                + methodName
                  + "\nbut has not been marked @Optional or defined "
                  + (xmlSuite.getFileName() != null ? "in "
View Full Code Here

Examples of org.testng.TestNGException

    if(parameterNames.length == parameterTypes.length) return;
   
    for(int i= parameterTypes.length - 1; i >= parameterNames.length; i--) {
      if(!ITestContext.class.equals(parameterTypes[i])
          && !Method.class.equals(parameterTypes[i])) {
        throw new TestNGException( "Method " + methodName + " requires "
            + parameterTypes.length + " parameters but "
            + parameterNames.length
            + " were supplied in the "
            + methodAnnotation
            + " annotation.");       
View Full Code Here

Examples of org.testng.TestNGException

   
    if (null != dataProviderName && ! "".equals(dataProviderName)) {
      result = findDataProvider(clazz, finder, dataProviderName, dataProviderClass);
     
      if(null == result) {
        throw new TestNGException("Method " + m + " requires a @DataProvider named : "
            + dataProviderName + (dataProviderClass != null ? " in class " + dataProviderClass.getName() : "")
            );
      }
    }
View Full Code Here

Examples of org.testng.TestNGException

    for (Method m : ClassHelper.getAvailableMethods(cls)) {
      IDataProvider dp = (IDataProvider) finder.findAnnotation(m, IDataProvider.class);
      if (null != dp && (name.equals(dp.getName()) || name.equals(m.getName()))) {
        if (shouldBeStatic && (m.getModifiers() & Modifier.STATIC) == 0) {
          throw new TestNGException("DataProvider should be static: " + m);
        }
       
        return m;
      }
    }
View Full Code Here

Examples of org.testng.TestNGException

          }
        }
      }
     
      if (!foundAtLeastAMethod) {
        throw new TestNGException(mainMethod
            + "() is depending on nonexistent method " + currentRegexp);
      }
    }

    ITestNGMethod[] result = vResult.toArray(new ITestNGMethod[vResult.size()]);
View Full Code Here

Examples of org.testng.TestNGException

      // Go through all the parameters declared on this Data Provider and
      // make sure we have at most one Method and one ITestContext.
      // Anything else is an error
      Class<?>[] parameterTypes = dataProvider.getParameterTypes();
      if (parameterTypes.length > 2) {
        throw new TestNGException("DataProvider " + dataProvider + " cannot have more than two parameters");
      }
     
      int i = 0;
      for (Class<?> cls : parameterTypes) {
        boolean isTestInstance = annotationFinder.hasTestInstance(dataProvider, i++);
        if (cls.equals(Method.class)) {
          lParameters.add(testMethod);
        }
        else if (cls.equals(ITestContext.class)) {
          lParameters.add(testContext);
        }
        else if (isTestInstance) {
          lParameters.add(fedInstance);
        }
      }
      Object[] parameters = lParameters.toArray(new Object[lParameters.size()]);
     
      Class< ? > returnType = dataProvider.getReturnType();
      if (Object[][].class.isAssignableFrom(returnType)) {
        Object[][] oResult = (Object[][]) MethodHelper.invokeMethod(
            dataProvider, instance, parameters);
        method.setParameterInvocationCount(oResult.length);
        result = MethodHelper.createArrayIterator(oResult);
      }
      else if (Iterator.class.isAssignableFrom(returnType)) {
        // Already an Iterable<Object[]>, assign it directly
        result = (Iterator<Object[]>) MethodHelper.invokeMethod(dataProvider,
            instance, parameters);
      }
      else {
        throw new TestNGException("Data Provider " + dataProvider
            + " must return" + " either Object[][] or Iterator<Object>[], not "
            + returnType);
      }
    }
    catch (InvocationTargetException e) {
      throw new TestNGException(e);
    }
    catch (IllegalAccessException e) {
      throw new TestNGException(e);
    }

    return result;
  }
View Full Code Here

Examples of org.testng.TestNGException

      interpreter.set("method", method);
      interpreter.set("groups", groups);
      interpreter.set("testngMethod", tm);
    }
    catch(EvalError evalError) {
      throw new TestNGException("Cannot set BSH interpreter", evalError);
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.