@Test public void inline_in_criteria_evaluates() { List list = JsonPath.read(JSON_DOCUMENT, "$.store.book[?(@.category in ['reference', 'fiction'])]"); assertThat(list).hasSize(4); } }
@Test public void testArgumentsInTheMiddle() throws Exception { String[] args = new String[]{"-c", "foobar", "-b", "toast"}; CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "c")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("toast"); assertThat(evaluated.allArguments()).contains("foobar").hasSize(1); }
@Test public void testShouldUpdateDefinedButNotPureRender() { when(mSpecModel.isPureRender()).thenReturn(false); List<SpecModelValidationError> validationErrors = PureRenderValidation.validate(mSpecModel); assertThat(validationErrors).hasSize(1); assertThat(validationErrors.get(0).element).isEqualTo(mDelegateMethodRepresentedObject1); assertThat(validationErrors.get(0).message).isEqualTo( "Specs defining a method annotated with @ShouldUpdate should also set " + "isPureRender = true in the top-level spec annotation."); } }
@Test public void testSingleDash() throws Exception { String[] args = new String[]{"--copt", "-b", "-", "-a", "-"}; CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("-"); assertThat(getBooleanOption(evaluated, "c")).isTrue(); assertThat(evaluated.allArguments()).contains("-").hasSize(1); }
@Test public void issue_predicate_or_has_lower_priority_than_and() { String json = "{\n" + " \"logs\": [\n" + " {\n" + " \"id\": 2\n" + " }\n" + " ]\n" + "}"; List<String> result = JsonPath.read(json, "$.logs[?(@.x && @.y || @.id)]"); assertThat(result).hasSize(1); }
@Test public void testOptionalPropWithDefault() { when(mPropModel1.isOptional()).thenReturn(false); when(mPropModel1.hasDefault(any(ImmutableList.class))).thenReturn(true); List<SpecModelValidationError> validationErrors = PropValidation.validate( mSpecModel, PropValidation.COMMON_PROP_NAMES, PropValidation.VALID_COMMON_PROPS); assertThat(validationErrors).hasSize(1); assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1); assertThat(validationErrors.get(0).message).isEqualTo( "name1 is not optional so it should not be declared with a default value."); }
@Test public void testSimpleShort() throws Exception { String[] args = new String[]{ "-a", "-b", "toast", "foo", "bar"}; CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("toast"); assertThat(getBooleanOption(evaluated, "c")).isFalse(); assertThat(evaluated.allArguments()).contains("foo", "bar").hasSize(2); }
@Test public void assert_arrays_can_be_read() { /* Object result = reader.read("$.store.book"); assertThat(reader.configuration().jsonProvider().isArray(result)).isTrue(); assertThat(reader.configuration().jsonProvider().length(result)).isEqualTo(4); */ assertThat(reader.read("$.store.book", List.class)).hasSize(4); }
@Test public void testPropMarkedOverrideCommonButNotCommon() { when(mPropModel1.overrideCommonPropBehavior()).thenReturn(true); when(mPropModel1.isCommonProp()).thenReturn(false); List<SpecModelValidationError> validationErrors = PropValidation.validate( mSpecModel, PropValidation.COMMON_PROP_NAMES, PropValidation.VALID_COMMON_PROPS); assertThat(validationErrors).hasSize(1); assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1); assertThat(validationErrors.get(0).message) .isEqualTo("overrideCommonPropBehavior may only be true is isCommonProp is true."); }
@Test public void testBursting() throws Exception { String[] args = new String[]{"-acbtoast", "foo", "bar"}; CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isTrue(); assertThat(getBooleanOption(evaluated, "c")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("toast"); assertThat(evaluated.allArguments()).hasSize(2).contains("foo", "bar"); }
@Test public void all_books() throws Exception { Assertions.assertThat(JsonPath.<List<Object>>read(DOCUMENT, "$..book")).hasSize(1); }
@Test public void testPropMarkedCommonWithoutCommonName() { when(mPropModel1.getName()).thenReturn("badName"); when(mPropModel1.isCommonProp()).thenReturn(true); List<SpecModelValidationError> validationErrors = PropValidation.validate( mSpecModel, PropValidation.COMMON_PROP_NAMES, PropValidation.VALID_COMMON_PROPS); assertThat(validationErrors).hasSize(1); assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1); assertThat(validationErrors.get(0).message) .isEqualTo( "Prop with isCommonProp and name badName is incorrectly defined - see PropValidation.java for a list of common props that may be used."); }
@Test public void testSimpleLong() throws Exception { String[] args = new String[]{"--enable-a", "--bfile", "toast", "foo", "bar"}; CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("toast"); assertThat(getStringOption(evaluated, "bfile")).isEqualTo("toast"); assertThat(getBooleanOption(evaluated, "c")).isFalse(); assertThat(evaluated.allArguments()).contains("foo", "bar").hasSize(2); }
@Test public void testLoadedViaServiceLoader() throws Exception { assertThat(StreamSupport.stream(ServiceLoader.load(SpanReporter.class).spliterator(), false) .filter(reporter -> reporter instanceof ElasticsearchSpanReporter)).hasSize(1); }
@Test public void testIncorrectTypeForResType() { when(mPropModel1.getResType()).thenReturn(ResType.BOOL); when(mPropModel1.getTypeName()).thenReturn(TypeName.INT); List<SpecModelValidationError> validationErrors = PropValidation.validate( mSpecModel, PropValidation.COMMON_PROP_NAMES, PropValidation.VALID_COMMON_PROPS); assertThat(validationErrors).hasSize(1); assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1); assertThat(validationErrors.get(0).message).isEqualTo( "A prop declared with resType BOOL must be one of the following types: " + "[boolean, java.lang.Boolean]."); }
@Test public void testOptionsWithDescription() { CLI cli = CLIConfigurator.define(CommandForDescriptionTest.class); assertThat(cli.getOptions()).hasSize(1); assertThat(find(cli.getOptions(), "option").getDescription()) .isEqualTo("This option is awesome"); }
@Test public void testUnrecognizedOptionWithBursting() throws Exception { String[] args = new String[]{"-adbtoast", "foo", "bar"}; CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(evaluated.allArguments()).contains("-adbtoast", "foo", "bar").hasSize(3); }
@Test public void testPropWithReservedName() { when(mPropModel1.getName()).thenReturn("layoutDirection"); List<SpecModelValidationError> validationErrors = PropValidation.validate( mSpecModel, PropValidation.COMMON_PROP_NAMES, PropValidation.VALID_COMMON_PROPS); assertThat(validationErrors).hasSize(1); assertThat(validationErrors.get(0).element).isEqualTo(mRepresentedObject1); assertThat(validationErrors.get(0).message) .isEqualTo( "'layoutDirection' is a reserved prop name used by the component's builder. Please" + " use another name or add \"isCommonProp\" to the Prop's definition."); }
@Test public void testCreation() { AmbiguousOptionException exception = new AmbiguousOptionException("foo", Arrays.asList(new Option().setLongName("foobar"), new Option().setLongName("foobaz"))); assertThat(exception.getOptions()).hasSize(2); assertThat(exception.getToken()).isEqualTo("foo"); assertThat(exception.getMessage()) .contains("Ambiguous argument in command line") .contains("'foo'") .contains("foobar").contains("foobaz"); }