本文整理汇总了Java中org.assertj.core.util.Maps类的典型用法代码示例。如果您正苦于以下问题:Java Maps类的具体用法?Java Maps怎么用?Java Maps使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Maps类属于org.assertj.core.util包,在下文中一共展示了Maps类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: discoveryClientWithMultiveEurekaServiceInstance
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
public void discoveryClientWithMultiveEurekaServiceInstance() {
EurekaServiceInstance firstServiceInstance = Mockito.mock(EurekaServiceInstance.class);
EurekaServiceInstance secondServiceInstance = Mockito.mock(EurekaServiceInstance.class);
Mockito.when(discoveryClient.getServices()).thenReturn(Lists.newArrayList("firstServiceId", "secondServiceId"));
Mockito.when(discoveryClient.getInstances("firstServiceId"))
.thenReturn(Lists.newArrayList(firstServiceInstance));
Mockito.when(discoveryClient.getInstances("secondServiceId"))
.thenReturn(Lists.newArrayList(secondServiceInstance));
Mockito.when(firstServiceInstance.getMetadata())
.thenReturn(Maps.newHashMap(CereebroMetadata.KEY_SNITCH_URI, "http://localhost:8081/cereebro"));
Mockito.when(secondServiceInstance.getMetadata())
.thenReturn(Maps.newHashMap(CereebroMetadata.KEY_SNITCH_URI, "http://localhost:8082/cereebro"));
DiscoveryClientSnitchRegistry snitchR = new DiscoveryClientSnitchRegistry(discoveryClient, objectMapper);
List<Snitch> snitches = snitchR.getAll();
Assertions.assertThat(snitches).isNotEmpty();
Assertions.assertThat(snitches).hasSize(2);
}
示例2: discoveryClientWithWrongUrlShouldUseServiceInstanceInfo
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
public void discoveryClientWithWrongUrlShouldUseServiceInstanceInfo() {
String serviceId = "serviceId";
URI uri = URI.create("http://service-instance-uri");
EurekaServiceInstance serviceInstanceMock = Mockito.mock(EurekaServiceInstance.class);
Mockito.when(serviceInstanceMock.getUri()).thenReturn(uri);
Mockito.when(serviceInstanceMock.getServiceId()).thenReturn(serviceId);
Mockito.when(discoveryClient.getServices()).thenReturn(Lists.newArrayList("serviceId"));
Mockito.when(discoveryClient.getInstances("serviceId")).thenReturn(Lists.newArrayList(serviceInstanceMock));
Mockito.when(serviceInstanceMock.getMetadata())
.thenReturn(Maps.newHashMap(CereebroMetadata.KEY_SNITCH_URI, ""));
DiscoveryClientSnitchRegistry registry = new DiscoveryClientSnitchRegistry(discoveryClient, objectMapper);
Assertions.assertThat(registry.getAll()).hasSize(1);
Snitch snitch = registry.getAll().get(0);
Assertions.assertThat(snitch).isInstanceOf(ServiceInstanceSnitch.class);
Assertions.assertThat(snitch.getUri()).isEqualTo(uri);
Component component = Component.of(serviceId, ComponentType.HTTP_APPLICATION);
SystemFragment expected = SystemFragment.of(ComponentRelationships.of(component, new HashSet<>()));
Assertions.assertThat(snitch.snitch()).isEqualTo(expected);
}
示例3: testProcessRequest_RegisterBroker
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
public void testProcessRequest_RegisterBroker() throws RemotingCommandException,
NoSuchFieldException, IllegalAccessException {
RemotingCommand request = genSampleRegisterCmd(true);
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(ctx.channel()).thenReturn(null);
RemotingCommand response = defaultRequestProcessor.processRequest(ctx, request);
assertThat(response.getCode()).isEqualTo(ResponseCode.SUCCESS);
assertThat(response.getRemark()).isNull();
RouteInfoManager routes = namesrvController.getRouteInfoManager();
Field brokerAddrTable = RouteInfoManager.class.getDeclaredField("brokerAddrTable");
brokerAddrTable.setAccessible(true);
BrokerData broker = new BrokerData();
broker.setBrokerName("broker");
broker.setBrokerAddrs((HashMap) Maps.newHashMap(new Long(2333), "10.10.1.1"));
assertThat((Map) brokerAddrTable.get(routes))
.contains(new HashMap.SimpleEntry("broker", broker));
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:25,代码来源:DefaultRequestProcessorTest.java
示例4: POST_replacesTheCredHubRefWithTheCredentialValue
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
public void POST_replacesTheCredHubRefWithTheCredentialValue() throws Exception {
JsonCredentialVersion jsonCredential = mock(JsonCredentialVersion.class);
doReturn(Maps.newHashMap("secret1", "secret1-value")).when(jsonCredential).getValue();
when(jsonCredential.getName()).thenReturn("/cred1");
JsonCredentialVersion jsonCredential1 = mock(JsonCredentialVersion.class);
doReturn(Maps.newHashMap("secret2", "secret2-value")).when(jsonCredential1).getValue();
when(jsonCredential1.getName()).thenReturn("/cred2");
doReturn(
Arrays.asList(jsonCredential)
).when(mockCredentialVersionDataService).findNByName("/cred1", 1);
doReturn(
Arrays.asList(jsonCredential1)
).when(mockCredentialVersionDataService).findNByName("/cred2", 1);
mockMvc.perform(makeValidPostRequest()).andDo(print()).andExpect(status().isOk())
.andExpect(jsonPath("$.pp-config-server[0].credentials.secret1")
.value(equalTo("secret1-value")))
.andExpect(jsonPath("$.pp-something-else[0].credentials.secret2")
.value(equalTo("secret2-value")));
}
示例5: testMap
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
public void testMap() {
Map<String, Object> foo = Maps.newHashMap();
foo.put("A", 1);
foo.put("B", 2);
foo.put("C", 3);
// 断言 map 不为空 size
assertThat(foo).isNotEmpty().hasSize(3);
// 断言 map 包含元素
assertThat(foo).contains(entry("A", 1), entry("B", 2));
// 断言 map 包含key
assertThat(foo).containsKeys("A", "B", "C");
// 断言 map 包含value
assertThat(foo).containsValue(3);
}
示例6: setup
import org.assertj.core.util.Maps; //导入依赖的package包/类
/**
* Configured the actions of 'created', 'updated', and 'deleted' for Book changes
* and which topic the book change events are published to
*/
@Before
public void setup(){
config = new StateChangeConfiguration();
final Map<String, String> eventMap = Maps.newHashMap();
eventMap.put("Created", TOPIC);
eventMap.put("Deleted", TOPIC);
eventMap.put("Updated", TOPIC);
final Map<String, Map<String, String>> modelMap = Maps.newHashMap();
modelMap.put(Book.class.getName(), eventMap);
config.setEvents(modelMap);
changePublisher = new StateChangePublisher(config, this.publisher);
}
示例7: onlyAcceptsCorrectValuesInPortAnnotation
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
public void onlyAcceptsCorrectValuesInPortAnnotation() throws Exception {
Pod invalidAnnotation = new Pod();
invalidAnnotation.setMetadata(new ObjectMeta());
invalidAnnotation.setStatus(new PodStatus());
invalidAnnotation.getStatus().setPodIP("10.116.0.8");
invalidAnnotation.getStatus().setPhase("Running");
invalidAnnotation.getMetadata().setAnnotations(
Maps.newHashMap(KubernetesInstanceDiscovery.PORT_ANNOTATION_KEY, "invalid-port"));
invalidAnnotation.getMetadata().setName("service-invalid-097fsd");
invalidAnnotation.getMetadata().setGenerateName("service-invalid-");
invalidAnnotation.getMetadata().setNamespace("production");
pods.clear();
pods.add(invalidAnnotation);
assertThat(discovery.getInstanceList().size()).isEqualTo(0);
}
示例8: usesPhasePropertyAsInstanceStatus
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
public void usesPhasePropertyAsInstanceStatus() throws Exception {
Pod invalidAnnotation = new Pod();
invalidAnnotation.setMetadata(new ObjectMeta());
invalidAnnotation.setStatus(new PodStatus());
invalidAnnotation.getStatus().setPodIP("10.116.0.8");
invalidAnnotation.getStatus().setPhase("Preparing");
invalidAnnotation.getMetadata().setAnnotations(
Maps.newHashMap(KubernetesInstanceDiscovery.PORT_ANNOTATION_KEY, "8080"));
invalidAnnotation.getMetadata().setName("service-preparing-097fsd");
invalidAnnotation.getMetadata().setGenerateName("service-preparing-");
invalidAnnotation.getMetadata().setNamespace("production");
pods.add(invalidAnnotation);
for (Instance instance: discovery.getInstanceList()) {
if (instance.getCluster().equals("production-service-preparing"))
assertThat(instance.isUp()).isFalse();
else
assertThat(instance.isUp()).isTrue();
}
}
示例9: removesPodTemplateHashFromClusterName
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
public void removesPodTemplateHashFromClusterName() throws Exception {
Pod deploymentPod = new Pod();
deploymentPod.setMetadata(new ObjectMeta());
deploymentPod.setStatus(new PodStatus());
deploymentPod.getStatus().setPodIP("10.116.0.8");
deploymentPod.getStatus().setPhase("Running");
deploymentPod.getMetadata().setAnnotations(
Maps.newHashMap(KubernetesInstanceDiscovery.PORT_ANNOTATION_KEY, "8080"));
deploymentPod.getMetadata().setLabels(
Maps.newHashMap(KubernetesInstanceDiscovery.POD_HASH_LABEL_KEY, "5432543253"));
deploymentPod.getMetadata().setName("service-depl-5432543253-097fsd");
deploymentPod.getMetadata().setGenerateName("service-depl-5432543253-");
deploymentPod.getMetadata().setNamespace("production");
pods.add(deploymentPod);
Optional<Instance> instanceOptional = discovery.getInstanceList().stream()
.filter(instance -> instance.getCluster().equals("production-service-depl"))
.findAny();
assertThat(instanceOptional.isPresent()).isTrue();
}
示例10: itShouldApplyAlterationAsExpected
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
/**
* Verify that the protected method `applyAlteration` does what it should, and that discounts are changed
* proportionally to the size of the alteration
*/
public void itShouldApplyAlterationAsExpected() {
final Object id1 = UUID.randomUUID();
final Object id2 = UUID.randomUUID();
final List<TestItem> itemList = Arrays.asList(
createItem(id1, 100L, 30f, new BigDecimal("4")),
createItem(id2, 300L, 10f, new BigDecimal("4"))
);
final Cart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> originalCart =
new Cart<TestItem, TestDiscount, TestDiscount, TestServiceCharge>(
itemList,
Arrays.asList(new TestDiscount(100L, null, BigDecimal.ONE)),
new TestServiceCharge(30f, 100L, 10d, BigDecimal.ONE)
);
final Cart<AlteredCartItem, AlteredCartDiscount, AlteredCartDiscount, AlteredCartServiceCharge> alteredCart =
originalCart.applyAlteration(Maps.newHashMap(id1, BigDecimal.valueOf(4).negate()));
assertEquals(originalCart.getValue(), 1750L);
assertEquals(alteredCart.getValue(), 1284L);
assertEquals(originalCart.getDiscountValue().longValue(), 100L);
assertEquals(alteredCart.getDiscountValue().longValue(), 75L);
}
示例11: itShouldGroupAlteredVatsAsExpected
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
public void itShouldGroupAlteredVatsAsExpected() {
final Object id1 = UUID.randomUUID();
final Object id2 = UUID.randomUUID();
final Object id3 = UUID.randomUUID();
final Cart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> cart = createCart(
createItem(id1, 100L, 6f, new BigDecimal("2")),
createItem(id2, 200L, 12f, new BigDecimal("2")),
createItem(id3, 300L, 25f, new BigDecimal("2"))
);
final AlterationCart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> cartAlteration = cart
.createAlterationCart(null, Maps.newHashMap(id1, BigDecimal.valueOf(1).negate()));
final SortedMap<Float, VatGroupValues> groupedVats = cartAlteration.groupValuesByVatPercentage();
//only the 6% VAT should be affected, and represent a value: the rest is not affected by this alteration
assertEquals(-5L, groupedVats.get(6f).getActualVatValue());
assertEquals(0L, groupedVats.get(12f).getActualVatValue());
assertEquals(0L, groupedVats.get(25f).getActualVatValue());
}
示例12: itShouldHandleFullDrainageForFixedLineItemDiscounts
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
/**
* Verifies that there is no amounts remaining after all items has been removed, even if there was a fixed line item
* discount
*/
public void itShouldHandleFullDrainageForFixedLineItemDiscounts() {
final Object id1 = UUID.randomUUID();
final Cart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> cart = createCart(
new TestItem(id1, "Main thing", 1L, 30f, BigDecimal.valueOf(1L), new TestDiscount(10L, null, BigDecimal.ONE))
);
final long originalValue = cart.getValue();
final Map<Object, BigDecimal> currentRefund = Maps.newHashMap(id1, BigDecimal.ONE.negate());
final AlterationCart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> alterationCart = cart
.createAlterationCart(null, currentRefund);
final long alterationValue = alterationCart.getValue();
assertEquals(originalValue, -1 * alterationValue);
}
示例13: itShouldHandleFullDrainageForPercentageLineItemDiscounts
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
/**
* Verifies that there is no amounts remaining after all items has been removed, even if there was a percentage line
* item discount
*/
public void itShouldHandleFullDrainageForPercentageLineItemDiscounts() {
final Object id = UUID.randomUUID();
final Cart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> cart = createCart(
new TestItem(id, "Main thing", 1L, 30f, BigDecimal.valueOf(1L), new TestDiscount(null, 50d, BigDecimal.ONE))
);
final long originalValue = cart.getValue();
final Map<Object, BigDecimal> currentRefund = Maps.newHashMap(id, BigDecimal.ONE.negate());
final AlterationCart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> alterationCart2 = cart
.createAlterationCart(null, currentRefund);
final long alterationValue2 = alterationCart2.getValue();
assertEquals(originalValue, -1 * alterationValue2);
}
示例14: itShouldHandleFullDrainageForFixedCartWideDiscounts
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
/**
* Verifies that there is no amounts remaining after all items has been removed, even if there was a fixed cart wide
* discount
*/
public void itShouldHandleFullDrainageForFixedCartWideDiscounts() {
final Object id = UUID.randomUUID();
final TestDiscount discount = new TestDiscount(10L, null, BigDecimal.ONE);
final Cart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> cart
= new Cart<TestItem, TestDiscount, TestDiscount, TestServiceCharge>(
Arrays.asList(createItem(id, 10L, 30f, BigDecimal.valueOf(2L))),
Arrays.asList(discount),
null
);
final long originalValue = cart.getValue();
final Map<Object, BigDecimal> firstAlteration = Maps.newHashMap(id, BigDecimal.ONE.negate());
final Map<Object, BigDecimal> currentRefund = Maps.newHashMap(id, BigDecimal.ONE.negate());
final AlterationCart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> firstAlterationCart = cart
.createAlterationCart(null, firstAlteration);
final AlterationCart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> secondAlterationCart = cart
.createAlterationCart(Arrays.asList(firstAlteration), currentRefund);
final long firstAlterationValue = firstAlterationCart.getValue();
final long secondalterationValue = secondAlterationCart.getValue();
assertEquals(originalValue, -1 * (firstAlterationValue + secondalterationValue));
}
示例15: itShouldHandleFullDrainageForPercentageCartWideDiscounts
import org.assertj.core.util.Maps; //导入依赖的package包/类
@Test
/**
* Verifies that there is no amounts remaining after all items has been removed, even if there was a percentage cart
* wide discount
*/
public void itShouldHandleFullDrainageForPercentageCartWideDiscounts() {
final Object id = UUID.randomUUID();
final TestDiscount discount = new TestDiscount(null, 20d, BigDecimal.ONE);
final Cart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> cart
= new Cart<TestItem, TestDiscount, TestDiscount, TestServiceCharge>(
Arrays.asList(createItem(id, 10L, 30f, BigDecimal.valueOf(2L))),
Arrays.asList(discount),
null
);
final long originalValue = cart.getValue();
final Map<Object, BigDecimal> firstAlteration = Maps.newHashMap(id, BigDecimal.ONE.negate());
final Map<Object, BigDecimal> currentRefund = Maps.newHashMap(id, BigDecimal.ONE.negate());
final AlterationCart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> firstAlterationCart = cart
.createAlterationCart(null, firstAlteration);
final AlterationCart<TestItem, TestDiscount, TestDiscount, TestServiceCharge> secondAlterationCart = cart
.createAlterationCart(Arrays.asList(firstAlteration), currentRefund);
final long firstAlterationValue = firstAlterationCart.getValue();
final long secondalterationValue = secondAlterationCart.getValue();
assertEquals(originalValue, -1 * (firstAlterationValue + secondalterationValue));
}