DefaultTextPatternService implements TextPatternService { @Override public Map<String, List<String>> getRequiredValues( TextPattern pattern ) { return ImmutableMap.<String, List<String>>builder() .put( "REQUIRED", pattern.getSegments() .stream() .filter( this::isRequired ) .map( segment -> segment.getMethod().name() ) .collect( Collectors.toList() ) ) .put( "OPTIONAL", pattern.getSegments() .stream() .filter( this::isOptional ) .map( (segment -> segment.getMethod().name()) ) .collect( Collectors.toList() ) ) .build(); }  @Override String resolvePattern( TextPattern pattern, Map<String, String> values ); @Override Map<String, List<String>> getRequiredValues( TextPattern pattern ); @Override boolean validate( TextPattern textPattern, String text );  }
@Test public void testGetRequiredValues() { List<String> required = textPatternService.getRequiredValues( pattern ).get( "REQUIRED" ); assertFalse( required.contains( "TEXT" ) ); assertFalse( required.contains( "CURRENT_DATE" ) ); assertTrue( required.contains( "ORG_UNIT_CODE" ) ); assertFalse( required.contains( "SEQUENTIAL" ) ); assertEquals( 1, required.size() ); }
@Test public void testGetOptionalValues() { List<String> optional = textPatternService.getRequiredValues( pattern ).get( "OPTIONAL" ); assertFalse( optional.contains( "TEXT" ) ); assertFalse( optional.contains( "CURRENT_DATE" ) ); assertFalse( optional.contains( "ORG_UNIT_CODE" ) ); assertTrue( optional.contains( "SEQUENTIAL" ) ); assertEquals( 1, optional.size() ); }