|
| 1 | +package org.codehaus.plexus.interpolation; |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright 2001-2008 Codehaus Foundation. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +import junit.framework.TestCase; |
| 20 | + |
| 21 | +import static java.util.Collections.singletonMap; |
| 22 | + |
| 23 | +public class FeedbackingValueSourceTest |
| 24 | + extends TestCase |
| 25 | +{ |
| 26 | + |
| 27 | + public void testStandalone() |
| 28 | + { |
| 29 | + ValueSource valueSource = new FeedbackingValueSource(); |
| 30 | + assertNull( valueSource.getValue( "test" ) ); |
| 31 | + assertEquals( 1, valueSource.getFeedback().size() ); |
| 32 | + assertEquals( "'test' not resolved", valueSource.getFeedback().iterator().next() ); |
| 33 | + } |
| 34 | + |
| 35 | + public void testAfterResolvedExpression() throws InterpolationException |
| 36 | + { |
| 37 | + StringSearchInterpolator interpolator = new StringSearchInterpolator(); |
| 38 | + interpolator.addValueSource( new MapBasedValueSource( singletonMap( "key", "val" ) ) ); |
| 39 | + interpolator.addValueSource( new FeedbackingValueSource() ); |
| 40 | + assertEquals( "val", interpolator.interpolate( "${key}" ) ); |
| 41 | + assertTrue( interpolator.getFeedback().isEmpty() ); |
| 42 | + } |
| 43 | + |
| 44 | + public void testBeforeResolvedExpression() throws InterpolationException |
| 45 | + { |
| 46 | + StringSearchInterpolator interpolator = new StringSearchInterpolator(); |
| 47 | + interpolator.addValueSource( new FeedbackingValueSource("Resolving ${expression}") ); |
| 48 | + interpolator.addValueSource( new MapBasedValueSource( singletonMap( "key", "val" ) ) ); |
| 49 | + assertEquals( "val", interpolator.interpolate( "${key}" ) ); |
| 50 | + assertEquals( 1, interpolator.getFeedback().size() ); |
| 51 | + assertEquals( "Resolving key", interpolator.getFeedback().iterator().next() ); |
| 52 | + } |
| 53 | + |
| 54 | + public void testAfterNotResolvedExpression() throws InterpolationException |
| 55 | + { |
| 56 | + StringSearchInterpolator interpolator = new StringSearchInterpolator(); |
| 57 | + interpolator.addValueSource( new MapBasedValueSource( singletonMap( "key", "val" ) ) ); |
| 58 | + interpolator.addValueSource( new FeedbackingValueSource() ); |
| 59 | + assertEquals( "${other-key}", interpolator.interpolate( "${other-key}" ) ); |
| 60 | + assertEquals( 1, interpolator.getFeedback().size() ); |
| 61 | + } |
| 62 | +} |
0 commit comments