private static ImmutableList<Fix> buildValidReplacements( Multimap<Integer, JCVariableDecl> potentialReplacements, Function<JCVariableDecl, Fix> replacementFunction) { if (potentialReplacements.isEmpty()) { return ImmutableList.of(); } // Take all of the potential edit-distance replacements with the same minimum distance, // then suggest them as individual fixes. return potentialReplacements.get(Collections.min(potentialReplacements.keySet())).stream() .map(replacementFunction) .collect(toImmutableList()); }
Class<?> testedClass = classMap.get(testedClassName.get()); if (testedClass != null) { testClasses.put(testedClass, cls); NEXT_CANDIDATE: for (Class<?> candidate : Iterables.filter(candidateClasses, classFilter)) { for (Class<?> testClass : testClasses.get(candidate)) { if (hasTest(testClass, explicitTestNames)) {
@Test public void testParseQueryWithKeysThatRequireDecoding() { Multimap<String, String> parsedMap = queryParser().apply("network%5B0%5D.id=23&network%5B0%5D.address=192.168.0.1"); assertEquals(parsedMap.get("network[0].id"), ImmutableSet.of("23")); assertEquals(parsedMap.get("network[0].address"), ImmutableSet.of("192.168.0.1")); }
public void testAccountInDomainStatic() { ListUsageRecordsOptions options = accountInDomain("fred", "42"); assertEquals(ImmutableSet.of("fred"), options.buildQueryParameters().get("account")); assertEquals(ImmutableSet.of("42"), options.buildQueryParameters().get("domainid")); }
for (Type type : typeManager.getTypes()) { if (type.isComparable()) { if (!functions.canResolveOperator(HASH_CODE, BIGINT, ImmutableList.of(type))) { missingOperators.put(type, HASH_CODE); if (!functions.canResolveOperator(EQUAL, BOOLEAN, ImmutableList.of(type, type))) { missingOperators.put(type, EQUAL); if (!functions.canResolveOperator(NOT_EQUAL, BOOLEAN, ImmutableList.of(type, type))) { missingOperators.put(type, NOT_EQUAL); for (Type type : missingOperators.keySet()) { messages.add(format("%s missing for %s", missingOperators.get(type), type));
public void testBuilderPutAllIterable() { ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.putAll("foo", Arrays.asList(1, 2, 3)); builder.putAll("bar", Arrays.asList(4, 5)); builder.putAll("foo", Arrays.asList(6, 7)); Multimap<String, Integer> multimap = builder.build(); assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo")); assertEquals(ImmutableSet.of(4, 5), multimap.get("bar")); assertEquals(7, multimap.size()); }
/** * Create permissions, note that permissionType + targetId should be unique */ @Transactional public Set<Permission> createPermissions(Set<Permission> permissions) { Multimap<String, String> targetIdPermissionTypes = HashMultimap.create(); for (Permission permission : permissions) { targetIdPermissionTypes.put(permission.getTargetId(), permission.getPermissionType()); } for (String targetId : targetIdPermissionTypes.keySet()) { Collection<String> permissionTypes = targetIdPermissionTypes.get(targetId); List<Permission> current = permissionRepository.findByPermissionTypeInAndTargetId(permissionTypes, targetId); Preconditions.checkState(CollectionUtils.isEmpty(current), "Permission with permissionType %s targetId %s already exists!", permissionTypes, targetId); } Iterable<Permission> results = permissionRepository.saveAll(permissions); return FluentIterable.from(results).toSet(); }
@Test public void testGetHeaders() throws Exception { HttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "www.google.com"); nettyRequest.headers().add("key1", "value1"); nettyRequest.headers().add("key1", "value2"); nettyRequest.headers().add("key2", "value1"); RecordedHttpRequestBuilder recordedHttpRequestBuilder = new RecordedHttpRequestBuilder(nettyRequest); Multimap<String, String> headers = recordedHttpRequestBuilder.getHeaders(); Assert.assertEquals(headers.size(), 3); Assert.assertTrue(headers.get("key1").contains("value1")); Assert.assertTrue(headers.get("key1").contains("value2")); Assert.assertTrue(headers.get("key2").contains("value1")); }
public void testBuilderPutAllMultimap() { Multimap<String, Integer> toPut = LinkedListMultimap.create(); toPut.put("foo", 1); toPut.put("bar", 4); toPut.put("foo", 2); toPut.put("foo", 3); Multimap<String, Integer> moreToPut = LinkedListMultimap.create(); moreToPut.put("foo", 6); moreToPut.put("bar", 5); moreToPut.put("foo", 7); ImmutableSetMultimap.Builder<String, Integer> builder = ImmutableSetMultimap.builder(); builder.putAll(toPut); builder.putAll(moreToPut); Multimap<String, Integer> multimap = builder.build(); assertEquals(ImmutableSet.of(1, 2, 3, 6, 7), multimap.get("foo")); assertEquals(ImmutableSet.of(4, 5), multimap.get("bar")); assertEquals(7, multimap.size()); }
@Implementation(minSdk = KITKAT) @HiddenApi public List<PackageOps> getOpsForPackage(int uid, String packageName, int[] ops) { Set<Integer> opFilter = new HashSet<>(); if (ops != null) { for (int op : ops) { opFilter.add(op); } } List<OpEntry> opEntries = new ArrayList<>(); for (Integer op : mStoredOps.get(getInternalKey(uid, packageName))) { if (opFilter.isEmpty() || opFilter.contains(op)) { opEntries.add(toOpEntry(op)); } } return ImmutableList.of(new PackageOps(packageName, uid, opEntries)); }
MockRemoteTaskFactory remoteTaskFactory = new MockRemoteTaskFactory(remoteTaskExecutor, remoteTaskScheduledExecutor); int task = 0; for (Node node : assignments.keySet()) { TaskId taskId = new TaskId("test", 1, task); task++; MockRemoteTaskFactory.MockRemoteTask remoteTask = remoteTaskFactory.createTableScanTask(taskId, node, ImmutableList.copyOf(assignments.get(node)), nodeTaskMap.createPartitionedSplitCountTracker(node, taskId)); remoteTask.startSplits(25); nodeTaskMap.addTask(node, remoteTask); for (Node node : assignments.keySet()) { RemoteTask remoteTask = taskMap.get(node); remoteTask.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder() .putAll(new PlanNodeId("sourceId"), assignments.get(node)) .build()); for (Node node : assignments.keySet()) { RemoteTask remoteTask = taskMap.get(node); remoteTask.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder() .putAll(new PlanNodeId("sourceId"), assignments.get(node)) .build()); RemoteTask remoteTask = taskMap.get(node); remoteTask.addSplits(ImmutableMultimap.<PlanNodeId, Split>builder() .putAll(new PlanNodeId("sourceId"), assignments.get(node)) .build());
map.put("bar", 2); Multimap<String, Integer> multimap = HashMultimap.create(); multimap.put("foo", 1); multimap.put("bar", 2); Multimap<String, Integer> multimapView = Multimaps.forMap(map); new EqualsTester().addEqualityGroup(multimap, multimapView).addEqualityGroup(map).testEquals(); Multimap<String, Integer> multimap2 = HashMultimap.create(); multimap2.put("foo", 1); assertFalse(multimapView.equals(multimap2)); multimap2.put("bar", 1); assertTrue(multimapView.containsValue(1)); assertTrue(multimapView.containsEntry("bar", 2)); assertEquals(Collections.singleton(1), multimapView.get("foo")); assertEquals(Collections.singleton(2), multimapView.get("bar")); try { multimapView.put("baz", 3); assertFalse(multimapView.containsKey("bar")); assertFalse(map.containsKey("bar")); assertEquals(map.keySet(), multimapView.keySet()); assertEquals(map.keySet(), multimapView.keys().elementSet()); assertThat(multimapView.keys()).contains("foo");
public static void verifyEventsForTestMethodsRunInTheSameThread(Class<?> testClass, String suiteName, String testName) { for (Method method : testClass.getMethods()) { boolean isTestMethod = false; Annotation[] annotations = method.getDeclaredAnnotations(); for(Annotation a : annotations) { if(Test.class.isAssignableFrom(a.getClass())) { isTestMethod = true; } } if (method.getDeclaringClass().equals(testClass) && isTestMethod) { Multimap<Object, EventLog> testMethodEventLogs = getTestMethodEventLogsForMethod(suiteName, testName, testClass.getCanonicalName(), method.getName()); for (Object instanceKey : testMethodEventLogs.keySet()) { long threadId = -1; for (EventLog eventLog : testMethodEventLogs.get(instanceKey)) { if (threadId == -1) { threadId = eventLog.getThreadId(); } else { assertEquals(eventLog.getThreadId(), threadId, "All of the method level events for the test " + "method " + method.getName() + " in the test class " + testClass.getCanonicalName() + " for the test " + suiteName + " should be run in the same thread"); } } } } } }
public void testNewMultimap() { // The ubiquitous EnumArrayBlockingQueueMultimap CountingSupplier<Queue<Integer>> factory = new QueueSupplier(); Map<Color, Collection<Integer>> map = Maps.newEnumMap(Color.class); Multimap<Color, Integer> multimap = Multimaps.newMultimap(map, factory); assertEquals(0, factory.count); multimap.putAll(Color.BLUE, asList(3, 1, 4)); assertEquals(1, factory.count); multimap.putAll(Color.RED, asList(2, 7, 1, 8)); assertEquals(2, factory.count); assertEquals("[3, 1, 4]", multimap.get(Color.BLUE).toString()); Multimap<Color, Integer> ummodifiable = Multimaps.unmodifiableMultimap(multimap); assertEquals("[3, 1, 4]", ummodifiable.get(Color.BLUE).toString()); Collection<Integer> collection = multimap.get(Color.BLUE); assertEquals(collection, collection); assertFalse(multimap.keySet() instanceof SortedSet); assertFalse(multimap.asMap() instanceof SortedMap); }
@Test public void testWithBlockDeviceMappingStatic() { BlockDeviceMapping mapping = new BlockDeviceMapping.MapNewVolumeToDevice("/dev/sda1", 120, true); RunInstancesOptions options = withBlockDeviceMappings(ImmutableSet .<BlockDeviceMapping> of(mapping)); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.DeviceName"), ImmutableList.of("/dev/sda1")); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.Ebs.VolumeSize"), ImmutableList.of("120")); assertEquals(options.buildFormParameters().get("BlockDeviceMapping.1.Ebs.DeleteOnTermination"), ImmutableList.of("true")); }
public void testAttributeStatic() { CreateQueueOptions options = attribute("DelaySeconds", "1"); assertEquals(ImmutableSet.of("DelaySeconds"), options.buildFormParameters().get("Attribute.1.Name")); assertEquals(ImmutableSet.of("1"), options.buildFormParameters().get("Attribute.1.Value")); }
/** Confirm that get() returns a List that doesn't implement RandomAccess. */ public void testGetRandomAccess() { Multimap<String, Integer> multimap = create(); multimap.put("foo", 1); multimap.put("foo", 3); assertFalse(multimap.get("foo") instanceof RandomAccess); assertFalse(multimap.get("bar") instanceof RandomAccess); }
private static <K, V> String countDuplicatesMultimap(Multimap<K, V> multimap) { List<String> entries = new ArrayList<>(); for (K key : multimap.keySet()) { entries.add(key + "=" + SubjectUtils.countDuplicates(multimap.get(key))); } StringBuilder sb = new StringBuilder(); sb.append("{"); Joiner.on(", ").appendTo(sb, entries); sb.append("}"); return sb.toString(); }