### Question:
TextUtil { public static String getSection( final String pagedata, final int section ) throws IllegalArgumentException { int tags = 0; int start = 0; int previous = 0; while( ( start = pagedata.indexOf( "----", start ) ) != -1 ) { if( ++tags == section ) { return pagedata.substring( previous, start ); } start += 4; while (start < pagedata.length() && pagedata.charAt( start ) == '-') { start++; } previous = start; } if( ++tags == section ) { return pagedata.substring( previous ); } throw new IllegalArgumentException( "There is no section no. " + section + " on the page." ); } private  TextUtil(); static String urlEncodeUTF8( final String text ); static String urlDecodeUTF8( final String utf8 ); static String urlEncode( final String data, final String encoding ); static String urlDecode( final String data, final String encoding ); static String replaceEntities( String src ); static String replaceString( final String orig, final String src, final String dest ); static String replaceString( final String orig, final int start, final int end, final String text ); static String replaceStringCaseUnsensitive( final String orig, final String src, final String dest ); static int parseIntParameter( final String value, final int defvalue ); static int getIntegerProperty( final Properties props, final String key, final int defVal ); static boolean getBooleanProperty( final Properties props, final String key, final boolean defval ); static String getStringProperty( final Properties props, final String key, final String defval ); static String getRequiredProperty( final Properties props, final String key ); static String getCanonicalFilePathProperty( final Properties props, final String key, final String defval ); static boolean isPositive( String val ); static String normalizePostData( final String postData ); static String beautifyString( final String s ); static String beautifyString( final String s, final String space ); static String cleanString( String text, final String allowedChars ); static Properties createProperties( final String[] values ); static int countSections( final String pagedata ); static String getSection( final String pagedata, final int section ); static String repeatString( final String what, final int times ); static String native2Ascii( final String s ); static String toHexString( final byte[] bytes ); static boolean isNumber( String s ); static String generateRandomPassword(); static final int PASSWORD_LENGTH; static final String LEGACY_CHARS_ALLOWED; static final String PUNCTUATION_CHARS_ALLOWED; }### Answer:
@Test public void testGetSection1() { final String src = "Single page."; Assertions.assertEquals( src, TextUtil.getSection(src,1), "section 1" ); Assertions.assertThrows( IllegalArgumentException.class, () -> TextUtil.getSection( src, 5 ) ); Assertions.assertThrows( IllegalArgumentException.class, () -> TextUtil.getSection( src, -1 ) ); }
@Test public void testGetSection2() { final String src = "First section\n----\nSecond section\n\n----\n\nThird section"; Assertions.assertEquals( "First section\n", TextUtil.getSection(src,1), "section 1" ); Assertions.assertEquals( "\nSecond section\n\n", TextUtil.getSection(src,2), "section 2" ); Assertions.assertEquals( "\n\nThird section", TextUtil.getSection(src,3), "section 3" ); Assertions.assertThrows( IllegalArgumentException.class, () -> TextUtil.getSection( src, 4 ) ); }
@Test public void testGetSection3() { final String src = "----\nSecond section\n----"; Assertions.assertEquals( "", TextUtil.getSection(src,1), "section 1" ); Assertions.assertEquals( "\nSecond section\n", TextUtil.getSection(src,2), "section 2" ); Assertions.assertEquals( "", TextUtil.getSection(src,3), "section 3" ); Assertions.assertThrows( IllegalArgumentException.class, () -> TextUtil.getSection( src, 4 ) ); }
@Test public void testGetSectionWithMoreThanFourDashes() { final String src = "----------------\nSecond section\n----"; Assertions.assertEquals( "\nSecond section\n", TextUtil.getSection(src, 2), "section 2" ); }