/** * Merge a single hint into a map of hints, possibly creating and copying * all hints into a new map, or otherwise if the map of hints is empty, * creating a new single entry map. * @param hints a map of hints to be merge * @param hintName the hint name to merge * @param hintValue the hint value to merge * @return a single map with all hints */ public static Map<String, Object> merge(Map<String, Object> hints, String hintName, Object hintValue) { if (hints.isEmpty()) { return Collections.singletonMap(hintName, hintValue); } else { Map<String, Object> result = new HashMap<>(hints.size() + 1); result.putAll(hints); result.put(hintName, hintValue); return result; } }
@SuppressWarnings("unchecked") private static Map<String, Object> convertLiquibase(List<Map<String, Object>> reports) { Map<String, Object> liquibaseBeans = reports.stream() .sequential() .collect(toMap(r -> (String) r.get("name"), r -> singletonMap("changeSets", LegacyEndpointConverters.convertLiquibaseChangesets( (List<Map<String, Object>>) r.get("changeLogs"))))); return singletonMap("contexts", singletonMap("application", singletonMap("liquibaseBeans", liquibaseBeans))); }
@Test public void resolveExtensions() { Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON); MappingMediaTypeFileExtensionResolver resolver = new MappingMediaTypeFileExtensionResolver(mapping); List<String> extensions = resolver.resolveFileExtensions(MediaType.APPLICATION_JSON); assertEquals(1, extensions.size()); assertEquals("json", extensions.get(0)); }
@Test @SuppressWarnings("unchecked") public void headerArgumentResolution() { Map<String, Object> headers = Collections.singletonMap("foo", "bar"); Message<?> message = createMessage("/pre/headers", headers); this.messageHandler.registerHandler(this.testController); this.messageHandler.handleMessage(message); assertEquals("headers", this.testController.method); assertEquals("bar", this.testController.arguments.get("foo")); assertEquals("bar", ((Map<String, Object>) this.testController.arguments.get("headers")).get("foo")); }
@Test public void defaultUriVarsSpr14147() { Map<String, String> defaultUriVars = new HashMap<>(2); defaultUriVars.put("host", "api.example.com"); defaultUriVars.put("port", "443"); DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(); factory.setDefaultUriVariables(defaultUriVars); URI uri = factory.expand("https://{host}:{port}/v42/customers/{id}", singletonMap("id", 123L)); assertEquals("https://api.example.com:443/v42/customers/123", uri.toString()); }
@Test public void testNullConfigValue() throws Exception { ConfigTransformerResult result = configTransformer.transform(Collections.singletonMap(MY_KEY, null)); Map<String, String> data = result.data(); Map<String, Long> ttls = result.ttls(); assertNull(data.get(MY_KEY)); assertTrue(ttls.isEmpty()); }
@Test public void resolveKeyFromRegistrations() { ServerWebExchange exchange = createExchange("html"); Map<String, MediaType> mapping = Collections.emptyMap(); RequestedContentTypeResolver resolver = new ParameterContentTypeResolver(mapping); List<MediaType> mediaTypes = resolver.resolveMediaTypes(exchange); assertEquals(Collections.singletonList(new MediaType("text", "html")), mediaTypes); mapping = Collections.singletonMap("HTML", MediaType.APPLICATION_XHTML_XML); resolver = new ParameterContentTypeResolver(mapping); mediaTypes = resolver.resolveMediaTypes(exchange); assertEquals(Collections.singletonList(new MediaType("application", "xhtml+xml")), mediaTypes); }
@Test public void testAddWhenOtherHasMoreResourcesThanThis() { NormalizedResources resources = new NormalizedResources(normalize(Collections.emptyMap())); NormalizedResources addedResources = new NormalizedResources(normalize(Collections.singletonMap(gpuResourceName, 1))); resources.add(addedResources); Map<String, Double> normalizedMap = resources.toNormalizedMap(); assertThat(normalizedMap.get(gpuResourceName), is(1.0)); }
/** * Renew to add new schema. * * @param schemaAddedEvent schema add changed event */ @Subscribe public synchronized void renew(final SchemaAddedEvent schemaAddedEvent) { logicSchemas.put(schemaAddedEvent.getShardingSchemaName(), createLogicSchema(schemaAddedEvent.getShardingSchemaName(), Collections.singletonMap(schemaAddedEvent.getShardingSchemaName(), DataSourceConverter.getDataSourceParameterMap(schemaAddedEvent.getDataSourceConfigurations())), schemaAddedEvent.getRuleConfiguration(), true)); }
@Override protected Map<Integer, TypeDefinition> resolveInitializationTypes(ArgumentHandler argumentHandler) { return adviceMethod.getReturnType().represents(void.class) ? Collections.<Integer, TypeDefinition>emptyMap() : Collections.<Integer, TypeDefinition>singletonMap(argumentHandler.exit(), adviceMethod.getReturnType()); }
@Test public void testCouldHoldWithMissingResource() { NormalizedResources resources = new NormalizedResources(normalize(Collections.emptyMap())); NormalizedResources resourcesToCheck = new NormalizedResources(normalize(Collections.singletonMap(gpuResourceName, 1))); boolean couldHold = resources.couldHoldIgnoringSharedMemory(resourcesToCheck, 100, 1); assertThat(couldHold, is(false)); }
@Test public void optionalHeaderArgumentResolutionWhenPresent() { Map<String, Object> headers = Collections.singletonMap("foo", "bar"); Message<?> message = createMessage("/pre/optionalHeaders", headers); this.messageHandler.registerHandler(this.testController); this.messageHandler.handleMessage(message); assertEquals("optionalHeaders", this.testController.method); assertEquals("bar", this.testController.arguments.get("foo1")); assertEquals("bar", this.testController.arguments.get("foo2")); }
@Test public void singleKey() { kh.getKeyList().addAll(singletonList(singletonMap("key", 1))); assertEquals("single key should be returned", 1, kh.getKey().intValue()); }
@Test(expected = IllegalArgumentException.class) public void pathVariableNotFound() { MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://example.com")); Map<String, String> pathVariables = Collections.singletonMap("foo", "bar"); exchange.getAttributes().put(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE, pathVariables); DefaultServerRequest request = new DefaultServerRequest(exchange, messageReaders); request.pathVariable("baz"); }
@Test public void modelAttributes() { Map<String, String> model = Collections.singletonMap("foo", "bar"); Mono<RenderingResponse> result = RenderingResponse.create("foo") .modelAttributes(model).build(); StepVerifier.create(result) .expectNextMatches(response -> "bar".equals(response.model().get("foo"))) .expectComplete() .verify(); }
@SuppressWarnings("unchecked") private static Map<String, Object> convertFlyway(List<Map<String, Object>> reports) { Map<String, Object> flywayBeans = reports.stream() .sequential() .collect(toMap(r -> (String) r.get("name"), r -> singletonMap("migrations", LegacyEndpointConverters.convertFlywayMigrations( (List<Map<String, Object>>) r.get("migrations"))))); return singletonMap("contexts", singletonMap("application", singletonMap("flywayBeans", flywayBeans))); }
@Test public void testEmptyList() { AbstractConfig conf; ConfigDef configDef = new ConfigDef().define("a", Type.LIST, "", new ConfigDef.NonNullValidator(), Importance.HIGH, "doc"); conf = new AbstractConfig(configDef, Collections.emptyMap()); assertEquals(Collections.emptyList(), conf.getList("a")); conf = new AbstractConfig(configDef, Collections.singletonMap("a", "")); assertEquals(Collections.emptyList(), conf.getList("a")); conf = new AbstractConfig(configDef, Collections.singletonMap("a", "b,c,d")); assertEquals(Arrays.asList("b", "c", "d"), conf.getList("a")); }
/** * Renew to add new schema. * * @param schemaAddedEvent schema add changed event */ @Subscribe public synchronized void renew(final SchemaAddedEvent schemaAddedEvent) { logicSchemas.put(schemaAddedEvent.getShardingSchemaName(), createLogicSchema(schemaAddedEvent.getShardingSchemaName(), Collections.singletonMap(schemaAddedEvent.getShardingSchemaName(), DataSourceConverter.getDataSourceParameterMap(schemaAddedEvent.getDataSourceConfigurations())), schemaAddedEvent.getRuleConfiguration(), true)); }
public void testEnumMap() { EnumMap<SomeEnum, Integer> map = Maps.newEnumMap(SomeEnum.class); assertEquals(Collections.emptyMap(), map); map.put(SomeEnum.SOME_INSTANCE, 0); assertEquals(Collections.singletonMap(SomeEnum.SOME_INSTANCE, 0), map); }
@Test public void testErrorCountsWithTopLevelError() { Map<TopicPartition, Errors> errors = new HashMap<>(); errors.put(new TopicPartition("foo", 0), Errors.NONE); errors.put(new TopicPartition("foo", 1), Errors.NOT_LEADER_FOR_PARTITION); StopReplicaResponse response = new StopReplicaResponse(Errors.UNKNOWN_SERVER_ERROR, errors); assertEquals(Collections.singletonMap(Errors.UNKNOWN_SERVER_ERROR, 2), response.errorCounts()); }