WholeDocumentLanguageDispatchAnnotator implements Annotator { @Override public AnnotatedText annotate(CharSequence input) { throw new UnsupportedOperationException("No AnnotatedText provided."); } WholeDocumentLanguageDispatchAnnotator(Map<LanguageCode, Annotator> delegates); @Override AnnotatedText annotate(CharSequence input); @Override AnnotatedText annotate(AnnotatedText input);  }
@Test public void dispatch() throws Exception { AnnotatedText.Builder textBuilder = new AnnotatedText.Builder(); LanguageDetection.DetectionResult.Builder drBuilder = new LanguageDetection.DetectionResult.Builder(LanguageCode.FRENCH); LanguageDetection.Builder ldBuilder = new LanguageDetection.Builder(0, 0, Lists.newArrayList(drBuilder.build())); textBuilder.wholeDocumentLanguageDetection(ldBuilder.build()); final AnnotatedText fraText = textBuilder.build(); textBuilder = new AnnotatedText.Builder(); drBuilder = new LanguageDetection.DetectionResult.Builder(LanguageCode.SPANISH); ldBuilder = new LanguageDetection.Builder(0, 0, Lists.newArrayList(drBuilder.build())); textBuilder.wholeDocumentLanguageDetection(ldBuilder.build()); final AnnotatedText spaText = textBuilder.build(); final AnnotatedText fraResult = new AnnotatedText.Builder().build(); final AnnotatedText spaResult = new AnnotatedText.Builder().build(); new Expectations() { { fraAnnotator.annotate(fraText); returns(fraResult); spaAnnotator.annotate(spaText); returns(spaResult); } }; WholeDocumentLanguageDispatchAnnotatorBuilder builder = new WholeDocumentLanguageDispatchAnnotatorBuilder(); builder.delegate(LanguageCode.FRENCH, fraAnnotator); builder.delegate(LanguageCode.SPANISH, spaAnnotator); Annotator delegator = builder.build(); delegator.annotate(fraText); delegator.annotate(spaText); }
@Test(expected = RosetteUnsupportedLanguageException.class) public void noHandler() throws Exception { AnnotatedText.Builder textBuilder = new AnnotatedText.Builder(); LanguageDetection.DetectionResult.Builder drBuilder = new LanguageDetection.DetectionResult.Builder(LanguageCode.FRENCH); LanguageDetection.Builder ldBuilder = new LanguageDetection.Builder(0, 0, Lists.newArrayList(drBuilder.build())); textBuilder.wholeDocumentLanguageDetection(ldBuilder.build()); final AnnotatedText fraText = textBuilder.build(); WholeDocumentLanguageDispatchAnnotatorBuilder builder = new WholeDocumentLanguageDispatchAnnotatorBuilder(); Annotator delegator = builder.build(); delegator.annotate(fraText); }