### Question:
SubstringNode extends LeafNode { public static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ) { StringBuilder buf = new StringBuilder(); if ( initialPattern != null ) { buf.append( '^' ).append( Pattern.quote( initialPattern ) ); } if ( anyPattern != null ) { for ( int i = 0; i < anyPattern.length; i++ ) { buf.append( ".*" ).append( Pattern.quote( anyPattern[i] ) ); } } if ( finalPattern != null ) { buf.append( ".*" ).append( Pattern.quote( finalPattern ) ); } else { buf.append( ".*" ); } return Pattern.compile( buf.toString() ); } SubstringNode( AttributeType attributeType, String initialPattern, String finalPattern );  SubstringNode( String attribute, String initialPattern, String finalPattern );  SubstringNode( AttributeType attribute );  SubstringNode( String attributeType );  SubstringNode( List<String> anyPattern, AttributeType attributeType, String initialPattern,
        String finalPattern );  SubstringNode( List<String> anyPattern, String attribute, String initialPattern, String finalPattern ); static Pattern getRegex( String initialPattern, String[] anyPattern, String finalPattern ); @Override ExprNode clone(); final String getInitial(); void setInitial( String initialPattern ); final String getFinal(); void setFinal( String finalPattern ); final List<String> getAny(); void setAny( List<String> anyPattern ); void addAny( String anyPattern ); final Pattern getRegex( Normalizer normalizer ); @Override boolean equals( Object obj ); @Override int hashCode(); @Override String toString();  }### Answer:
@Test public void testGetRegexpEmpty() throws Exception { Pattern pattern = SubstringNode.getRegex( "", new String[] { "" }, "" ); boolean b1 = pattern.matcher( "" ).matches(); assertTrue( b1 ); }
@Test public void testGetRegexpInitial() throws Exception { Pattern pattern = SubstringNode.getRegex( "Test", new String[] { "" }, "" ); boolean b1 = pattern.matcher( "Test just a test" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "test just a test" ).matches(); assertFalse( b3 ); }
@Test public void testGetRegexpFinal() throws Exception { Pattern pattern = SubstringNode.getRegex( "", new String[] { "" }, "Test" ); boolean b1 = pattern.matcher( "test just a Test" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "test just a test" ).matches(); assertFalse( b3 ); }
@Test public void testGetRegexpAny() throws Exception { Pattern pattern = SubstringNode.getRegex( "", new String[] { "just", "a" }, "" ); boolean b1 = pattern.matcher( "test just a Test" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "test just A test" ).matches(); assertFalse( b3 ); }
@Test public void testGetRegexpFull() throws Exception { Pattern pattern = SubstringNode.getRegex( "Test", new String[] { "just", "a" }, "test" ); boolean b1 = pattern.matcher( "Test (this is) just (truly !) a (little) test" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "Test (this is) just (truly !) A (little) test" ).matches(); assertFalse( b3 ); }
@Test public void testGetRegexpWithLdapFilterSpecialChars() throws Exception { Pattern[] patterns = new Pattern[] { SubstringNode.getRegex( null, new String[] { "(" }, null ), SubstringNode.getRegex( null, new String[] { ")" }, null ), SubstringNode.getRegex( null, new String[] { "*" }, null ), SubstringNode.getRegex( null, new String[] { "\\" }, null ), }; for ( Pattern pattern : patterns ) { boolean b1 = pattern.matcher( "a(b*c\\d)e" ).matches(); assertTrue( b1 ); boolean b3 = pattern.matcher( "Test test" ).matches(); assertFalse( b3 ); } }