|  | 
|  | 1 | +/* | 
|  | 2 | + * Hibernate Validator, declare and validate application constraints | 
|  | 3 | + * | 
|  | 4 | + * License: Apache License, Version 2.0 | 
|  | 5 | + * See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>. | 
|  | 6 | + */ | 
|  | 7 | +package org.hibernate.validator.test.internal.bootstrap; | 
|  | 8 | + | 
|  | 9 | +import static org.testng.Assert.assertSame; | 
|  | 10 | + | 
|  | 11 | +import java.util.Locale; | 
|  | 12 | + | 
|  | 13 | +import javax.validation.Configuration; | 
|  | 14 | +import javax.validation.MessageInterpolator; | 
|  | 15 | +import javax.validation.Validation; | 
|  | 16 | +import javax.validation.ValidatorFactory; | 
|  | 17 | + | 
|  | 18 | +import org.testng.annotations.Test; | 
|  | 19 | + | 
|  | 20 | +/** | 
|  | 21 | + * @author Steven Walters | 
|  | 22 | + * @author Guillaume Smet | 
|  | 23 | + */ | 
|  | 24 | +public class ConfigurationReuseHibernateValidatorTest { | 
|  | 25 | + | 
|  | 26 | +	public static class MessageInterpolatorImpl implements MessageInterpolator { | 
|  | 27 | + | 
|  | 28 | +		private final String prefix; | 
|  | 29 | + | 
|  | 30 | +		public MessageInterpolatorImpl(String prefix) { | 
|  | 31 | +			this.prefix = prefix; | 
|  | 32 | +		} | 
|  | 33 | + | 
|  | 34 | +		@Override | 
|  | 35 | +		public String interpolate(String messageTemplate, Context context) { | 
|  | 36 | +			return prefix + ": " + messageTemplate; | 
|  | 37 | +		} | 
|  | 38 | + | 
|  | 39 | +		@Override | 
|  | 40 | +		public String interpolate(String messageTemplate, Context context, Locale locale) { | 
|  | 41 | +			return prefix + ": " + messageTemplate + locale.toLanguageTag(); | 
|  | 42 | +		} | 
|  | 43 | + | 
|  | 44 | +		public String toString() { | 
|  | 45 | +			return getClass().getSimpleName() + prefix; | 
|  | 46 | +		} | 
|  | 47 | +	} | 
|  | 48 | + | 
|  | 49 | +	@Test | 
|  | 50 | +	public void testMessageInterpolatorChange() { | 
|  | 51 | +		Configuration<?> config = Validation.byDefaultProvider().configure(); | 
|  | 52 | +		MessageInterpolator interpolator1 = new MessageInterpolatorImpl( "One" ); | 
|  | 53 | +		MessageInterpolator interpolator2 = new MessageInterpolatorImpl( "Two" ); | 
|  | 54 | +		ValidatorFactory factory1 = config.messageInterpolator( interpolator1 ).buildValidatorFactory(); | 
|  | 55 | +		ValidatorFactory factory2 = config.messageInterpolator( interpolator2 ).buildValidatorFactory(); | 
|  | 56 | +		assertSame( factory1.getMessageInterpolator(), interpolator1 ); | 
|  | 57 | +		assertSame( factory2.getMessageInterpolator(), interpolator2 ); | 
|  | 58 | +	} | 
|  | 59 | +} | 
0 commit comments