Refine search
@Test public void issue_predicate_brackets_must_change_priorities() { String json = "{\n" + " \"logs\": [\n" + " {\n" + " \"id\": 2\n" + " }\n" + " ]\n" + "}"; List<String> result = JsonPath.read(json, "$.logs[?(@.message && (@.id == 1 || @.id == 2))].id"); assertThat(result).isEmpty(); result = JsonPath.read(json, "$.logs[?((@.id == 2 || @.id == 1) && @.message)].id"); assertThat(result).isEmpty(); }
@Test public void path2() { List<Object> result = JsonPath.read("{\"a\":[{\"b\":1,\"c\":2},{\"b\":5,\"c\":2}]}", "a[?(@.b==4)].c"); Assertions.assertThat(result).isEmpty(); }
@Test public void issue_114_c() { String json = "{ \"p\": [\"valp\", \"valq\", \"valr\"] }"; List<String> result = read(json, "$.p[?(@[0] == 'valp')]"); assertThat(result).isEmpty(); }
private void assertThatLogsDoNotContain(LoggerLevel loggerLevel, String message) { assertThat(logTester.logs(loggerLevel)).filteredOn(m -> m.contains(message)).isEmpty(); }
private void assertThatNoLogsFromRecovery(LoggerLevel loggerLevel) { assertThat(logTester.logs(loggerLevel)).filteredOn(m -> m.contains("Elasticsearch recovery - ")).isEmpty(); }
@Test public void no_path_ref_in_filter_hit_none() { List<String> res = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?('a' == 'b')].author"); assertThat(res).isEmpty(); }
@Test public void testOptionAndRequiredOption() throws Exception { String[] args = new String[]{"-a", "-b", "file"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isTrue(); assertThat(getStringOption(evaluated, "b")).isEqualTo("file"); assertThat(evaluated.allArguments()).isEmpty(); }
@Test public void applyExclusionsOnCoverageMeasures() throws IOException { File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\n\ncontent", StandardCharsets.UTF_8); File measures = new File(srcDir, "sample.xoo.measures"); FileUtils.write(measures, "lines_to_cover:2", StandardCharsets.UTF_8); AnalysisResult result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) .put("sonar.projectKey", "com.foo.project") .put("sonar.sources", "src") .build()) .execute(); Map<String, List<Measure>> allMeasures = result.allMeasures(); assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value") .containsOnly(tuple("lines_to_cover", 2)); result = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) .put("sonar.projectKey", "com.foo.project") .put("sonar.sources", "src") .put("sonar.coverage.exclusions", "src/sample.xoo") .build()) .execute(); allMeasures = result.allMeasures(); assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value") .isEmpty(); }
@Test public void testWithRequiredOption() throws Exception { String[] args = new String[]{"-b", "file"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); CommandLine evaluated = cli.parse(Arrays.asList(args)); assertThat(getBooleanOption(evaluated, "a")).isFalse(); assertThat((String) evaluated.getOptionValue("b")).isEqualTo("file"); assertThat(evaluated.allArguments()).isEmpty(); }
@Test public void patterns_can_be_evaluated_with_ignore_case() { List<String> resLeft = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?(@.category =~ /REFERENCE/)].author"); assertThat(resLeft).isEmpty(); resLeft = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?(@.category =~ /REFERENCE/i)].author"); assertThat(resLeft).containsExactly("Nigel Rees"); }
@Test public void testNegativeNumbers() throws CLIException { CLI cli = new DefaultCLI().setName("test"); Option[] options = new Option[]{ new TypedOption<Double>().setLongName("num").setSingleValued(true) .setType(Double.class) }; cli.addOptions(Arrays.asList(options)); CommandLine evaluated = cli.parse(Arrays.asList("--num", "-1.5")); assertThat(evaluated.cli().getOptions()).hasSize(1); assertThat(cli.getArguments()).isEmpty(); assertThat((double) evaluated.getOptionValue("num")).isEqualTo(-1.5d); evaluated = cli.parse(Collections.singletonList("--num=-1.5")); assertThat(evaluated.cli().getOptions()).hasSize(1); assertThat(cli.getArguments()).isEmpty(); assertThat((double) evaluated.getOptionValue("num")).isEqualTo(-1.5d); }
@Test public void a_path_can_be_deleted() { Object o = parse(JSON_DOCUMENT).delete("$.store.book[*].display-price").json(); List<Integer> result = parse(o).read("$.store.book[*].display-price"); assertThat(result).isEmpty(); }
@Test public void suggestions_without_query_should_not_contain_favorites_without_permission() { ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization)); doReturn(singletonList(project)).when(favoriteFinder).list(); componentIndexer.indexOnStartup(null); SuggestionsWsResponse response = ws.newRequest() .setMethod("POST") .executeProtobuf(SuggestionsWsResponse.class); assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .isEmpty(); }
@Test public void testCreateWithoutQuery() { controller.create().start().resume(); // skip menu inflation assertThat(ShadowSearchRecentSuggestions.recentQueries).isEmpty(); assertEquals(activity.getString(R.string.title_activity_search), activity.getDefaultTitle()); assertNull(activity.getSupportActionBar().getSubtitle()); }
.getSystemService(Context.NOTIFICATION_SERVICE)); ShadowNotification shadowNotification = shadowOf(notificationManager.getNotification(1)); assertThat(shadowNotification.getProgress()).isEqualTo(3); // self + kid 1 + readability assertThat(shadowNotification.getMax()).isEqualTo(104); // self + 2 kids + readability + web assertThat(notificationManager.getAllNotifications()).isEmpty();
@Test public void when_deep_scanning_non_array_subscription_is_ignored() { Object result = JsonPath.parse("{\"x\": [0,1,[0,1,2,3,null],null]}").read("$..[2][3]"); assertThat(result).asList().containsOnly(3); result = JsonPath.parse("{\"x\": [0,1,[0,1,2,3,null],null], \"y\": [0,1,2]}").read("$..[2][3]"); assertThat(result).asList().containsOnly(3); result = JsonPath.parse("{\"x\": [0,1,[0,1,2],null], \"y\": [0,1,2]}").read("$..[2][3]"); assertThat(result).asList().isEmpty(); }
assertThat(response.getResultsList()) .flatExtracting(Category::getItemsList) .hasSize(expectedNumberOfResults); assertThat(response.getResultsList()) .filteredOn(q -> q.getItemsCount() > 0) .isEmpty(); } else { assertThat(response.getResultsList()) .filteredOn(c -> "TRK".equals(c.getQ())) .extracting(Category::getMore)
@Test public void operations_can_chained() { Object o = parse(JSON_DOCUMENT) .delete("$.store.book[*].display-price") .set("$.store.book[*].category", "A") .json(); List<Integer> prices = parse(o).read("$.store.book[*].display-price"); List<String> categories = parse(o).read("$.store.book[*].category"); assertThat(prices).isEmpty(); assertThat(categories).containsExactly("A", "A", "A", "A"); }
@Test public void when_deep_scanning_illegal_property_access_is_ignored() { Object result = JsonPath.parse("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}").read("$..foo"); assertThat(result).asList().hasSize(2); result = JsonPath.parse("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}").read("$..foo.bar"); assertThat(result).asList().containsOnly(4); result = JsonPath.parse("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}").read("$..[*].foo.bar"); assertThat(result).asList().containsOnly(4); result = JsonPath.parse("{\"x\": {\"foo\": {\"baz\": 4}}, \"y\": {\"foo\": 1}}").read("$..[*].foo.bar"); assertThat(result).asList().isEmpty(); }
@Test public void testBindService() throws RemoteException { // no chrome installed should not bind service delegate.bindCustomTabsService(activity); assertThat(ShadowApplication.getInstance().getBoundServiceConnections()).isEmpty(); // bind service should create connection shadowOf(RuntimeEnvironment.application.getPackageManager()).addResolveInfoForIntent( new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity")); shadowOf(RuntimeEnvironment.application.getPackageManager()).addResolveInfoForIntent( new Intent("android.support.customtabs.action.CustomTabsService") .setPackage("com.android.chrome"), ShadowResolveInfo.newResolveInfo("label", "com.android.chrome", "DefaultActivity")); delegate.bindCustomTabsService(activity); List<ServiceConnection> connections = ShadowApplication.getInstance() .getBoundServiceConnections(); assertThat(connections).isNotEmpty(); // on service connected should create session and warm up client verify(service).warmup(anyLong()); assertNotNull(delegate.getSession()); verify(service).newSession(any(ICustomTabsCallback.class)); // may launch url should success when(service.mayLaunchUrl(any(), any(), any(), any())).thenReturn(true); assertTrue(delegate.mayLaunchUrl(Uri.parse("http://www.example.com"), null, null)); // on service disconnected should clear session delegate.unbindCustomTabsService(activity); assertNull(delegate.getSession()); }