@Test
  public void testEnglishAutoLoad() throws Exception {
    String oldModelCache =
        System.setProperty(ResourceObjectProviderBase.PROP_REPO_CACHE, "target/test-output/models");
    String oldOfflineMode =
        System.setProperty(
            ResourceObjectProviderBase.PROP_REPO_OFFLINE,
            ResourceObjectProviderBase.FORCE_AUTO_LOAD);

    try {
      TestRunner.autoloadModelsOnNextTestRun();
      runTest(
          "en",
          null,
          "This is a test .",
          new String[] {"DT", "VBZ", "DT", "NN", "."},
          new String[] {"ART", "V", "ART", "NN", "PUNC"});
    } finally {
      if (oldModelCache != null) {
        System.setProperty(ResourceObjectProviderBase.PROP_REPO_CACHE, oldModelCache);
      } else {
        System.getProperties().remove(ResourceObjectProviderBase.PROP_REPO_CACHE);
      }
      if (oldOfflineMode != null) {
        System.setProperty(ResourceObjectProviderBase.PROP_REPO_OFFLINE, oldOfflineMode);
      } else {
        System.getProperties().remove(ResourceObjectProviderBase.PROP_REPO_OFFLINE);
      }
    }
  }
  private JCas runTest(String text) throws Exception {
    AnalysisEngine engine = createEngine(LangDetectLanguageIdentifier.class);

    JCas aJCas = TestRunner.runTest(engine, "en", text);

    return aJCas;
  }
 /**
  * Simple test case: one stopword file.
  *
  * @throws UIMAException
  */
 @Test
 public void test() throws UIMAException {
   String[] expectedTokens = new String[] {"text", "containing", "stopwords", "."};
   AnalysisEngineDescription stopwordremover =
       createEngineDescription(
           StopWordRemover.class, StopWordRemover.PARAM_MODEL_LOCATION, STOPWORDSFILE_LOCATION1);
   JCas jcas = TestRunner.runTest(stopwordremover, LANGUAGE, TEXT);
   assertToken(expectedTokens, select(jcas, Token.class));
 }
  private void runTest(
      String language, String variant, String testDocument, String[] tags, String[] tagClasses)
      throws Exception {
    AnalysisEngine engine = createEngine(LbjPosTagger.class);

    JCas jcas = TestRunner.runTest(engine, language, testDocument);

    AssertAnnotations.assertPOS(tagClasses, tags, select(jcas, POS.class));
  }
  private JCas runTest(
      String language, String variant, String testDocument, String[] tags, String[] tagClasses)
      throws Exception {
    AnalysisEngine engine =
        createEngine(
            OpenNlpPosTagger.class,
            OpenNlpPosTagger.PARAM_VARIANT,
            variant,
            OpenNlpPosTagger.PARAM_PRINT_TAGSET,
            true);

    JCas jcas = TestRunner.runTest(engine, language, testDocument);

    AssertAnnotations.assertPOS(tagClasses, tags, select(jcas, POS.class));

    return jcas;
  }
  // Auxiliary method that sets up the analysis engine or pipeline used in the test.
  // Typically, we have multiple tests per unit test file that each invoke this method.
  private JCas runTest(String language, String variant, String testDocument) throws Exception {
    AnalysisEngineDescription postagger = createEngineDescription(Nlp4JPosTagger.class);
    AnalysisEngineDescription lemmatizer = createEngineDescription(Nlp4JLemmatizer.class);
    AnalysisEngineDescription ner =
        createEngineDescription(
            Nlp4JNamedEntityRecognizer.class,
            Nlp4JNamedEntityRecognizer.PARAM_VARIANT,
            variant,
            Nlp4JNamedEntityRecognizer.PARAM_PRINT_TAGSET,
            true);

    AnalysisEngineDescription engine = createEngineDescription(postagger, lemmatizer, ner);

    // Here we invoke the TestRunner which performs basic whitespace tokenization and
    // sentence splitting, creates a CAS, runs the pipeline, etc. TestRunner explicitly
    // disables automatic model loading. Thus, models used in unit tests must be explicitly
    // made dependencies in the pom.xml file.
    return TestRunner.runTest(engine, language, testDocument);
  }