@Test public void testClean() throws Exception { when( context.getResources().getStringArray( any( int.class ) ) ).thenReturn( new String[] { "THE ", "AN ", "A " } ); assertThat( ArticleCleaner.clean( context, "The quick brown fox..." ), equalTo( "quick brown fox..." ) ); assertThat( ArticleCleaner.clean( context, "THE QUICK BROWN FOX..." ), equalTo( "QUICK BROWN FOX..." ) ); assertThat( ArticleCleaner.clean( context, "the quick brown fox..." ), equalTo( "quick brown fox..." ) ); assertThat( ArticleCleaner.clean( context, "An interesting idea..." ), equalTo( "interesting idea..." ) ); assertThat( ArticleCleaner.clean( context, "an interesting idea..." ), equalTo( "interesting idea..." ) ); assertThat( ArticleCleaner.clean( context, "A stitch in time..." ), equalTo( "stitch in time..." ) ); assertThat( ArticleCleaner.clean( context, "a stitch in time..." ), equalTo( "stitch in time..." ) ); assertThat( ArticleCleaner.clean( context, "The An A ..." ), equalTo( "..." ) ); assertThat( ArticleCleaner.clean( context, "THE AN A ..." ), equalTo( "..." ) ); assertThat( ArticleCleaner.clean( context, "the an a ..." ), equalTo( "..." ) ); }
public static String clean( final Context context, String value ) { Log.d( TAG, "clean : enter" ); if( null == value || "".equals( value ) ) { return value; } String cleaned = value; String[] articles = context.getResources().getStringArray( R.array.articles ); String upper = cleaned.toUpperCase( Locale.getDefault() ); for( String article : articles ) { article = article + " "; Log.d( TAG, "clean : article=" + article + ", cleaned=" + cleaned ); if( upper.startsWith( article ) ) { Log.d( TAG, "clean : article found" ); cleaned = cleaned.substring( article.length() ).trim(); } } Log.d( TAG, "clean : exit - cleaned=" + cleaned ); return cleaned; }
ArticleCleaner { public static String clean( final Context context, String value ) { Log.d( TAG, "clean : enter" ); if( null == value || "".equals( value ) ) { return value; } String cleaned = value; String[] articles = context.getResources().getStringArray( R.array.articles ); String upper = cleaned.toUpperCase( Locale.getDefault() ); for( String article : articles ) { article = article + " "; Log.d( TAG, "clean : article=" + article + ", cleaned=" + cleaned ); if( upper.startsWith( article ) ) { Log.d( TAG, "clean : article found" ); cleaned = cleaned.substring( article.length() ).trim(); } } Log.d( TAG, "clean : exit - cleaned=" + cleaned ); return cleaned; } }
ArticleCleaner { public static String clean( final Context context, String value ) { Log.d( TAG, "clean : enter" ); if( null == value || "".equals( value ) ) { return value; } String cleaned = value; String[] articles = context.getResources().getStringArray( R.array.articles ); String upper = cleaned.toUpperCase( Locale.getDefault() ); for( String article : articles ) { article = article + " "; Log.d( TAG, "clean : article=" + article + ", cleaned=" + cleaned ); if( upper.startsWith( article ) ) { Log.d( TAG, "clean : article found" ); cleaned = cleaned.substring( article.length() ).trim(); } } Log.d( TAG, "clean : exit - cleaned=" + cleaned ); return cleaned; } private  ArticleCleaner(); }
ArticleCleaner { public static String clean( final Context context, String value ) { Log.d( TAG, "clean : enter" ); if( null == value || "".equals( value ) ) { return value; } String cleaned = value; String[] articles = context.getResources().getStringArray( R.array.articles ); String upper = cleaned.toUpperCase( Locale.getDefault() ); for( String article : articles ) { article = article + " "; Log.d( TAG, "clean : article=" + article + ", cleaned=" + cleaned ); if( upper.startsWith( article ) ) { Log.d( TAG, "clean : article found" ); cleaned = cleaned.substring( article.length() ).trim(); } } Log.d( TAG, "clean : exit - cleaned=" + cleaned ); return cleaned; } private  ArticleCleaner(); static String clean( final Context context, String value ); }
ArticleCleaner { public static String clean( final Context context, String value ) { Log.d( TAG, "clean : enter" ); if( null == value || "".equals( value ) ) { return value; } String cleaned = value; String[] articles = context.getResources().getStringArray( R.array.articles ); String upper = cleaned.toUpperCase( Locale.getDefault() ); for( String article : articles ) { article = article + " "; Log.d( TAG, "clean : article=" + article + ", cleaned=" + cleaned ); if( upper.startsWith( article ) ) { Log.d( TAG, "clean : article found" ); cleaned = cleaned.substring( article.length() ).trim(); } } Log.d( TAG, "clean : exit - cleaned=" + cleaned ); return cleaned; } private  ArticleCleaner(); static String clean( final Context context, String value );  }