Skip to content

Commit

Permalink
Fix build, reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
slachiewicz committed May 12, 2024
1 parent c9ee543 commit c74d84c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,24 @@
* <p>One of the obvious usages is to add FeedbackingValueSource as last value source to {@link Interpolator}
* to add feedback messages indicating not resolved expressions.</p>
*/
public class FeedbackingValueSource extends AbstractValueSource
{
public class FeedbackingValueSource extends AbstractValueSource {
private final String messagePattern;

public FeedbackingValueSource()
{
this( "'${expression}' not resolved" );
public FeedbackingValueSource() {
this("'${expression}' not resolved");
}

/**
* @param messagePattern could contain <code>${expression}</code> placeholder
*/
public FeedbackingValueSource( String messagePattern )
{
super( true );
public FeedbackingValueSource(String messagePattern) {
super(true);
this.messagePattern = messagePattern;
}

@Override
public Object getValue( String expression )
{
addFeedback( messagePattern.replace( "${expression}", expression ) );
public Object getValue(String expression) {
addFeedback(messagePattern.replace("${expression}", expression));
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,48 @@
* limitations under the License.
*/

import junit.framework.TestCase;
import org.junit.jupiter.api.Test;

import static java.util.Collections.singletonMap;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class FeedbackingValueSourceTest
extends TestCase
{
public class FeedbackingValueSourceTest {

public void testStandalone()
{
@Test
public void testStandalone() {
ValueSource valueSource = new FeedbackingValueSource();
assertNull( valueSource.getValue( "test" ) );
assertEquals( 1, valueSource.getFeedback().size() );
assertEquals( "'test' not resolved", valueSource.getFeedback().iterator().next() );
assertNull(valueSource.getValue("test"));
assertEquals(1, valueSource.getFeedback().size());
assertEquals("'test' not resolved", valueSource.getFeedback().iterator().next());
}

public void testAfterResolvedExpression() throws InterpolationException
{
@Test
public void testAfterResolvedExpression() throws InterpolationException {
StringSearchInterpolator interpolator = new StringSearchInterpolator();
interpolator.addValueSource( new MapBasedValueSource( singletonMap( "key", "val" ) ) );
interpolator.addValueSource( new FeedbackingValueSource() );
assertEquals( "val", interpolator.interpolate( "${key}" ) );
assertTrue( interpolator.getFeedback().isEmpty() );
interpolator.addValueSource(new MapBasedValueSource(singletonMap("key", "val")));
interpolator.addValueSource(new FeedbackingValueSource());
assertEquals("val", interpolator.interpolate("${key}"));
assertTrue(interpolator.getFeedback().isEmpty());
}

public void testBeforeResolvedExpression() throws InterpolationException
{
@Test
public void testBeforeResolvedExpression() throws InterpolationException {
StringSearchInterpolator interpolator = new StringSearchInterpolator();
interpolator.addValueSource( new FeedbackingValueSource("Resolving ${expression}") );
interpolator.addValueSource( new MapBasedValueSource( singletonMap( "key", "val" ) ) );
assertEquals( "val", interpolator.interpolate( "${key}" ) );
assertEquals( 1, interpolator.getFeedback().size() );
assertEquals( "Resolving key", interpolator.getFeedback().iterator().next() );
interpolator.addValueSource(new FeedbackingValueSource("Resolving ${expression}"));
interpolator.addValueSource(new MapBasedValueSource(singletonMap("key", "val")));
assertEquals("val", interpolator.interpolate("${key}"));
assertEquals(1, interpolator.getFeedback().size());
assertEquals("Resolving key", interpolator.getFeedback().iterator().next());
}

public void testAfterNotResolvedExpression() throws InterpolationException
{
@Test
public void testAfterNotResolvedExpression() throws InterpolationException {
StringSearchInterpolator interpolator = new StringSearchInterpolator();
interpolator.addValueSource( new MapBasedValueSource( singletonMap( "key", "val" ) ) );
interpolator.addValueSource( new FeedbackingValueSource() );
assertEquals( "${other-key}", interpolator.interpolate( "${other-key}" ) );
assertEquals( 1, interpolator.getFeedback().size() );
interpolator.addValueSource(new MapBasedValueSource(singletonMap("key", "val")));
interpolator.addValueSource(new FeedbackingValueSource());
assertEquals("${other-key}", interpolator.interpolate("${other-key}"));
assertEquals(1, interpolator.getFeedback().size());
}
}

0 comments on commit c74d84c

Please sign in to comment.