TextPatternValidationUtils { public static boolean validateValueType( TextPattern textPattern, ValueType valueType ) { if ( ValueType.TEXT.equals( valueType ) ) { return true; } else if ( ValueType.NUMBER.equals( valueType ) ) { boolean isAllNumbers = true; for ( TextPatternSegment segment : textPattern.getSegments() ) { isAllNumbers = isAllNumbers && isNumericOnly( segment ); } return isAllNumbers; } else { return false; } }  static boolean validateSegmentValue( TextPatternSegment segment, String value ); static boolean validateTextPatternValue( TextPattern textPattern, String value ); static long getTotalValuesPotential( TextPatternSegment generatedSegment ); static boolean validateValueType( TextPattern textPattern, ValueType valueType );  }
@Test public void testValidateValueType() { TextPattern textTP = new TextPattern( Lists.newArrayList( textSegment ) ); TextPattern numberTP = new TextPattern( Lists.newArrayList( sequentialSegment ) ); for ( ValueType valueType : ValueType.values() ) { if ( valueType.equals( ValueType.TEXT ) ) { assertTrue( TextPatternValidationUtils.validateValueType( textTP, valueType ) ); } else if ( valueType.equals( ValueType.NUMBER ) ) { assertTrue( TextPatternValidationUtils.validateValueType( numberTP, valueType ) ); } else { assertFalse( TextPatternValidationUtils.validateValueType( textTP, valueType ) ); assertFalse( TextPatternValidationUtils.validateValueType( numberTP, valueType ) ); } } }
@Test public void testValidateValueTypeWithDifferentTextPattern() { TextPattern just_text = new TextPattern( Lists.newArrayList( textSegment ) ); TextPattern just_random = new TextPattern( Lists.newArrayList( randomSegment ) ); TextPattern just_sequential = new TextPattern( Lists.newArrayList( sequentialSegment ) ); TextPattern just_orgunitcode = new TextPattern( Lists.newArrayList( orgUnitCodeSegment ) ); TextPattern just_currentdate = new TextPattern( Lists.newArrayList( currentDateSegment ) ); TextPattern text_and_numbers = new TextPattern( Lists.newArrayList( textSegment, sequentialSegment ) ); TextPattern just_numbers = new TextPattern( Lists.newArrayList( sequentialSegment ) ); assertTrue( TextPatternValidationUtils.validateValueType( just_text, ValueType.TEXT ) ); assertFalse( TextPatternValidationUtils.validateValueType( just_text, ValueType.NUMBER ) ); assertTrue( TextPatternValidationUtils.validateValueType( just_random, ValueType.TEXT ) ); assertFalse( TextPatternValidationUtils.validateValueType( just_random, ValueType.NUMBER ) ); assertTrue( TextPatternValidationUtils.validateValueType( just_sequential, ValueType.TEXT ) ); assertTrue( TextPatternValidationUtils.validateValueType( just_sequential, ValueType.NUMBER ) ); assertTrue( TextPatternValidationUtils.validateValueType( just_orgunitcode, ValueType.TEXT ) ); assertFalse( TextPatternValidationUtils.validateValueType( just_orgunitcode, ValueType.NUMBER ) ); assertTrue( TextPatternValidationUtils.validateValueType( just_currentdate, ValueType.TEXT ) ); assertFalse( TextPatternValidationUtils.validateValueType( just_currentdate, ValueType.NUMBER ) ); assertTrue( TextPatternValidationUtils.validateValueType( text_and_numbers, ValueType.TEXT ) ); assertFalse( TextPatternValidationUtils.validateValueType( text_and_numbers, ValueType.NUMBER ) ); assertTrue( TextPatternValidationUtils.validateValueType( just_numbers, ValueType.TEXT ) ); assertTrue( TextPatternValidationUtils.validateValueType( just_numbers, ValueType.NUMBER ) ); }