TextInstanceCreator extends BaseFunction { @SuppressWarnings({ "unchecked", "rawtypes" }) protected TextInstance<L> createInstance(TridentTuple tuple) { L label = this.withLabel ? (L) tuple.get(0) : null; String text = tuple.getString(this.withLabel ? 1 : 0); List<String> tokens = this.extractTokens(text); TextInstance<L> instance = new TextInstance(label, tokens); return instance; } TextInstanceCreator();  TextInstanceCreator(boolean withLabel);  TextInstanceCreator(boolean withLabel, TextTokenizer textAnalyser); @Override void execute(TridentTuple tuple, TridentCollector collector); boolean isWithLabel(); void setWithLabel(boolean withLabel); TextTokenizer getTextAnalyser(); void setTextAnalyser(TextTokenizer textAnalyser);  }
@Test public void testCreateInstanceWithLabel() { TextInstanceCreator<Integer> instanceCreator = new TextInstanceCreator<Integer>(true); Integer expectedLabel = 1; String expectedText = "I can't argue with some arguments on argus with argues"; TridentTuple tuple = mock(TridentTuple.class); when(tuple.get(0)).thenReturn(expectedLabel); when(tuple.getString(1)).thenReturn(expectedText); TextInstance<Integer> actualInstance = instanceCreator.createInstance(tuple); TextInstance<Integer> expectedInstance = new TextInstance<Integer>(expectedLabel, Arrays.asList("i", "can't", "argu", "some", "argument", "argu", "argu")); assertEquals(expectedInstance, actualInstance); }
@Test public void testCreateInstanceWithoutLabel() { TextInstanceCreator<Integer> instanceCreator = new TextInstanceCreator<Integer>(false); String expectedText = "I can't argue with some arguments on argus with argues"; TridentTuple tuple = mock(TridentTuple.class); when(tuple.getString(0)).thenReturn(expectedText); TextInstance<Integer> actualInstance = instanceCreator.createInstance(tuple); TextInstance<Integer> expectedInstance = new TextInstance<Integer>(Arrays.asList("i", "can't", "argu", "some", "argument", "argu", "argu")); assertEquals(expectedInstance, actualInstance); }