Package ch.inftec.ju.util.libs

Source Code of ch.inftec.ju.util.libs.PlexusInterpolationTest

package ch.inftec.ju.util.libs;

import java.util.Properties;

import org.codehaus.plexus.interpolation.AbstractValueSource;
import org.codehaus.plexus.interpolation.Interpolator;
import org.codehaus.plexus.interpolation.PropertiesBasedValueSource;
import org.codehaus.plexus.interpolation.RegexBasedInterpolator;
import org.codehaus.plexus.interpolation.ValueSource;
import org.junit.Assert;
import org.junit.Test;

/**
* Test Plexus interpolation.
* @author Martin Meyer <martin.meyer@inftec.ch>
*
*/
public class PlexusInterpolationTest {
  @Test
  public void testInterpolation_withoutSource() throws Exception {
    String s = "Hello ${name}";
   
    Interpolator i = new RegexBasedInterpolator();
    Assert.assertEquals("Hello ${name}", i.interpolate(s));
  }
 
  @Test
  public void testInterpolation_withPropertiesSource() throws Exception {
    String s = "Hello ${name}";
   
    Properties props = new Properties();
    props.put("name", "World");
    ValueSource vs = new PropertiesBasedValueSource(props);
   
    Interpolator i = new RegexBasedInterpolator();
    i.addValueSource(vs);
    Assert.assertEquals("Hello World", i.interpolate(s));
  }
 
  @Test
  public void testInterpolation_withCustomValueSource() throws Exception {
    String s = "Hello ${name}";
   
    ValueSource vs = new AbstractValueSource(false) {
      @Override
      public Object getValue(String expression) {
        return "World";
      }
    };
   
    Interpolator i = new RegexBasedInterpolator();
    i.addValueSource(vs);
    Assert.assertEquals("Hello World", i.interpolate(s));
  }
}
TOP

Related Classes of ch.inftec.ju.util.libs.PlexusInterpolationTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.