1 package com.atlassian.plugin.webresource.transformer;
2
3 import com.google.common.base.Function;
4
5 import java.util.regex.Matcher;
6 import java.util.regex.Pattern;
7
8 import junit.framework.TestCase;
9
10 public class TestSearchAndReplacer extends TestCase
11 {
12 public void testSimple()
13 {
14 final String input = "1 two 3 four 5";
15
16 final Function<Matcher, CharSequence> function = new Function<Matcher, CharSequence>()
17 {
18 public CharSequence apply(final Matcher m)
19 {
20 return new StringBuilder("$").append(m.group().toUpperCase()).append("\\");
21 }
22 };
23 final SearchAndReplacer grep = new SearchAndReplacer(Pattern.compile("[a-zA-Z]+"), function);
24 final String output = grep.replaceAll(input).toString();
25
26 assertEquals("1 $TWO\\ 3 $FOUR\\ 5", output);
27 }
28 }