1 package com.lexicalscope.jewel.cli; 2 3 import static com.lexicalscope.jewel.cli.ValidationFailureMatcher.validationError; 4 import static org.hamcrest.MatcherAssert.assertThat; 5 import static org.hamcrest.Matchers.contains; 6 import static org.junit.Assert.fail; 7 8 import org.junit.Test; 9 10 public class TestPattern { 11 public interface TestStringPattern { 12 @Option(pattern = "[a-z]+") String getOption(); 13 } 14 15 @Test public void testStringPatternMismatch() { 16 try { 17 CliFactory.parseArguments(TestStringPattern.class, "--option", "ABC"); 18 fail(); 19 } catch (final ArgumentValidationException e) { 20 assertThat(e.getValidationFailures(), contains(validationError( 21 ValidationFailureType.PatternMismatch, 22 "Cannot match (ABC) to pattern: --option /[a-z]+/"))); 23 } 24 } 25 26 @Test public void testStringPattern() throws ArgumentValidationException { 27 CliFactory.parseArguments(TestStringPattern.class, "--option", "abc"); 28 } 29 }