Java 类org.testng.TestNGException 实例源码

项目:testng-remote    文件:ServiceLoaderHelper.java   
public static RemoteTestNGFactory getFirst(Version version) {
    List<RemoteTestNGFactory> factories = new ArrayList<>();
    for (RemoteTestNGFactory factory : ServiceLoader.load(RemoteTestNGFactory.class)) {
        if (factory.accept(version)) {
            factories.add(factory);
        }
    }
    if (factories.isEmpty()) {
        throw new TestNGException(version + " is not a supported TestNG version");
    }
    if (factories.size() > 1) {
        System.err.println("[ServiceLoaderHelper] More than one working implementation for '" + version + "', we will use the first one");
    }

    Collections.sort(factories, new Comparator<RemoteTestNGFactory>() {
      @Override
      public int compare(RemoteTestNGFactory o1, RemoteTestNGFactory o2) {
        // the newest first
        return o2.getOrder() - o1.getOrder();
      }
    });

    return factories.get(0);
}
项目:golo-lang-insa-citilab-historical-reference    文件:EvaluationEnvironmentTest.java   
@Test
public void run_with_imports() throws Throwable {
  EvaluationEnvironment env = new EvaluationEnvironment().imports("java.lang.Math");
  String snippet = "return max(1, 2)";

  Object result = env.run(snippet);
  assertThat(result, instanceOf(Integer.class));
  assertThat((Integer) result, is(2));

  env.clearImports();
  try {
    env.run(snippet);
    throw new TestNGException("A RuntimeException should have been raised");
  } catch (RuntimeException ignored) {
  }
}
项目:golo-lang-insa-citilab-historical-reference    文件:EvaluationEnvironmentTest.java   
@Test
public void check_source_present_with_compilation_error() {
  EvaluationEnvironment env = new EvaluationEnvironment();
  try {
    env.def("boom");
    throw new TestNGException("A GoloCompilationException should have been raised");
  } catch (GoloCompilationException e) {
    assertThat(e.getSourceCode(), notNullValue());
    assertThat(e.getSourceCode(), both(containsString("boom")).and(containsString("module anonymous")));
  }
}
项目:ats-framework    文件:Test_BasicDataProvider.java   
@Test( dataProvider = "ConfigurableDataProvider", dataProviderClass = AtsDataProvider.class, expectedExceptions = TestNGException.class)
@TestOptions( dataFile = "Test_BasicDataProvider", dataSheet = TestDetails.FIRST_TEST_SCENARIO)
public void dataFile_noFileExtension( String user, String pswd, String subject ) {}
项目:ats-framework    文件:Test_BasicDataProvider.java   
@Test( dataProvider = "ConfigurableDataProvider", dataProviderClass = AtsDataProvider.class, expectedExceptions = TestNGException.class)
@TestOptions( dataFileFolder = TestDetails.DATA_FILES_FOLDER, dataFile = TestDetails.DATA_FILE1
                                                                         + "NON_EXISTING_FILE", dataSheet = TestDetails.FIRST_TEST_SCENARIO)
public void dataFile_wrongFile( String user, String pswd, String subject ) {}
项目:ats-framework    文件:Test_BasicDataProviderWithoutClassAnnotation.java   
@Test( dataProvider = "ConfigurableDataProvider", dataProviderClass = AtsDataProvider.class, expectedExceptions = TestNGException.class)
@TestOptions( dataFile = TestDetails.DATA_FILE2, dataSheet = TestDetails.FIRST_TEST_SCENARIO)
public void dataFileFolder_fromClassAnnotation( String user, String pswd, String subject ) {}
项目:ats-framework    文件:Test_BasicDataProviderWithoutClassAnnotation.java   
@Test( dataProvider = "ConfigurableDataProvider", dataProviderClass = AtsDataProvider.class, expectedExceptions = TestNGException.class)
@TestOptions( dataSheet = TestDetails.FIRST_TEST_SCENARIO)
public void dataFile_fromClasspath_negative( String user, String pswd, String subject ) {}
项目:qaf    文件:MethodHelper.java   
/**
 * Finds TestNG methods that the specified TestNG method depends upon
 * @param m TestNG method
 * @param methods list of methods to search for depended upon methods
 * @return list of methods that match the criteria
 */
protected static ITestNGMethod[] findDependedUponMethods(ITestNGMethod m,
    ITestNGMethod[] methods)
{
  String canonicalMethodName = calculateMethodCanonicalName(m);
  List<ITestNGMethod> vResult = Lists.newArrayList();
  String regexp = null;
  for (String fullyQualifiedRegexp : m.getMethodsDependedUpon()) {
    boolean foundAtLeastAMethod = false;

    if (null != fullyQualifiedRegexp) {
      // Escapes $ in regexps as it is not meant for end - line matching, but inner class matches.
      regexp = fullyQualifiedRegexp.replace("$", "\\$");
      boolean usePackage = regexp.indexOf('.') != -1;
      Pattern pattern = Pattern.compile(regexp);

      for (ITestNGMethod method : methods) {
        ConstructorOrMethod thisMethod = method.getConstructorOrMethod();
        String thisMethodName = thisMethod.getName();
        String methodName = usePackage ?
            calculateMethodCanonicalName(method)
            : thisMethodName;
        Pair<String, String> cacheKey = Pair.create(regexp, methodName);
        Boolean match = MATCH_CACHE.get(cacheKey);
        if (match == null) {
            match = pattern.matcher(methodName).matches();
            MATCH_CACHE.put(cacheKey, match);
        }
        if (match) {
          vResult.add(method);
          foundAtLeastAMethod = true;
        }
      }
    }

    if (!foundAtLeastAMethod) {
      if (m.ignoreMissingDependencies()) {
        continue;
      }
      if (m.isAlwaysRun()) {
        continue;
      }
      Method maybeReferringTo = findMethodByName(m, regexp);
      if (maybeReferringTo != null) {
        throw new TestNGException(canonicalMethodName + "() is depending on method "
            + maybeReferringTo + ", which is not annotated with @Test or not included.");
      }
      throw new TestNGException(canonicalMethodName
          + "() depends on nonexistent method " + regexp);
    }
  }//end for

  return vResult.toArray(new ITestNGMethod[vResult.size()]);
}
项目:testng-remote    文件:AbstractRemoteTestRunnerClient.java   
@Override
    public void run() {
      try {
        IMessage message = m_messageHub.receiveMessage();
        while (message != null) {
          switch (message.getType()) {
            case GENERIC:
              notifyStart((GenericMessage) message);
              break;
            case SUITE:
              notifySuiteEvents((SuiteMessage) message);
              break;
            case TEST:
              notifyTestEvents((TestMessage) message);
              break;
            case TEST_RESULT:
              notifyResultEvents((TestResultMessage) message);
              break;
            default:
                throw new TestNGException("Unknown message type:" + message);
          }
//          if (isRunning()) {
//            m_messageMarshaller.sendAck();
//          }
          message = m_messageHub.receiveMessage();
        }
      }
      finally {
        m_messageHub.shutDown();
        m_messageHub = null;
      }
//      try {
//        fServerSocket = new ServerSocket(fServerPort);
//        fSocket = fServerSocket.accept();
//        try {
//          m_inputReader = new BufferedReader(new InputStreamReader(fSocket.getInputStream(),
//                                                                     "UTF-8")); //$NON-NLS-1$
//        }
//        catch(UnsupportedEncodingException e) {
//          m_inputReader = new BufferedReader(new InputStreamReader(fSocket.getInputStream()));
//        }
//        try {
//          m_outputWriter = new PrintWriter(new OutputStreamWriter(fSocket.getOutputStream(), "UTF-8"),
//                                    true);
//        }
//        catch(UnsupportedEncodingException e1) {
//          m_outputWriter = new PrintWriter(new OutputStreamWriter(fSocket.getOutputStream()), true);
//        }
//        String message;
//        while((m_inputReader != null) && ((message = readMessage(m_inputReader)) != null)) {
//          receiveMessage(message);
//        }
//      }
//      catch(SocketException e) {
//        handleThrowable(e);
//      }
//      catch(IOException e) {
//        handleThrowable(e);
//      }
//      finally {
//        shutdown();
//      }
    }