### Question:
ViewTextCopierAnnotator extends JCasAnnotator_ImplBase { @Override public void process(final JCas jCas) throws AnalysisEngineProcessException { try { final JCas sourceView = jCas.getView(sourceViewName); JCas destinationView; try { destinationView = jCas.getView(destinationViewName); } catch (CASRuntimeException ce) { destinationView = jCas.createView(destinationViewName); } destinationView.setDocumentText(sourceView.getDocumentText()); } catch (CASException e) { throw new AnalysisEngineProcessException(e); } }  @Override void process(final JCas jCas); static final String PARAM_SOURCE_VIEW_NAME; static final String PARAM_DESTINATION_VIEW_NAME; }### Answer:
@Test public void testViewTextCopier() throws ResourceInitializationException, AnalysisEngineProcessException, CASException { String text = "sample text"; String sourceViewName = "SourceView"; String destinationViewName = "DestinationView"; jCas.setDocumentText(text); AnalysisEngine viewCreator = AnalysisEngineFactory.createEngine( ViewTextCopierAnnotator.class, typeSystemDescription, ViewTextCopierAnnotator.PARAM_SOURCE_VIEW_NAME, CAS.NAME_DEFAULT_SOFA, ViewTextCopierAnnotator.PARAM_DESTINATION_VIEW_NAME, destinationViewName); viewCreator.process(jCas); JCas destinationView = jCas.getView(destinationViewName); assertNotNull(destinationView); assertEquals(text, destinationView.getDocumentText()); jCas.reset(); jCas.setDocumentText(text); jCas.createView(destinationViewName); viewCreator.process(jCas); destinationView = jCas.getView(destinationViewName); assertNotNull(destinationView); assertEquals(text, destinationView.getDocumentText()); viewCreator = AnalysisEngineFactory.createEngine(ViewTextCopierAnnotator.class, typeSystemDescription, ViewTextCopierAnnotator.PARAM_SOURCE_VIEW_NAME, sourceViewName, ViewTextCopierAnnotator.PARAM_DESTINATION_VIEW_NAME, destinationViewName); jCas.reset(); JCas sourceView = jCas.createView(sourceViewName); sourceView.setDocumentText(text); viewCreator.process(jCas); destinationView = jCas.getView(destinationViewName); assertNotNull(destinationView); assertEquals(text, destinationView.getDocumentText()); assertNull(jCas.getDocumentText()); }
@Test public void testExceptions() throws ResourceInitializationException, AnalysisEngineProcessException { String sourceViewName = "SourceView"; String destinationViewName = "DestinationView"; AnalysisEngine viewCreator = AnalysisEngineFactory.createEngine( ViewTextCopierAnnotator.class, typeSystemDescription, ViewTextCopierAnnotator.PARAM_SOURCE_VIEW_NAME, sourceViewName, ViewTextCopierAnnotator.PARAM_DESTINATION_VIEW_NAME, destinationViewName); Throwable thrown = catchThrowable(() -> { HideOutput hider = null; try { hider = new HideOutput(); viewCreator.process(jCas); } finally { if (hider != null) { hider.restoreOutput(); } } }); assertThat(thrown) .as("Exception thrown when source view does not exist") .hasRootCauseInstanceOf(CASRuntimeException.class) .hasStackTraceContaining("No sofaFS with name SourceView found"); }