File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
guava/src/test/java/org/baeldung/guava Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 66import static org .junit .Assert .assertThat ;
77import static org .junit .Assert .assertTrue ;
88
9+ import java .nio .charset .Charset ;
10+ import java .nio .charset .CharsetEncoder ;
911import java .util .ArrayList ;
1012import java .util .List ;
1113import java .util .Map ;
1517import com .google .common .base .CharMatcher ;
1618import com .google .common .base .Function ;
1719import com .google .common .base .Joiner ;
20+ import com .google .common .base .Predicate ;
1821import com .google .common .base .Splitter ;
1922import com .google .common .collect .Iterables ;
2023import com .google .common .collect .Lists ;
@@ -196,4 +199,20 @@ public void whenCountCharInString_thenCorrect() {
196199 assertEquals (2 , result );
197200 }
198201
202+ @ Test
203+ public void whenRemoveCharsNotInCharset_thenRemoved () {
204+ final Charset charset = Charset .forName ("cp437" );
205+ final CharsetEncoder encoder = charset .newEncoder ();
206+
207+ final Predicate <Character > inRange = new Predicate <Character >() {
208+ @ Override
209+ public boolean apply (final Character c ) {
210+ return encoder .canEncode (c );
211+ }
212+ };
213+
214+ final String result = CharMatcher .forPredicate (inRange ).retainFrom ("helloは" );
215+ assertEquals ("hello" , result );
216+ }
217+
199218}
You can’t perform that action at this time.
0 commit comments