Java 类org.mockito.internal.matchers.apachecommons.ReflectionEquals 实例源码
项目:assertj-workshop
文件:CollectionAssertionsTest.java
@Test
public void foundHeroesShouldContainFrodoAndGandalf() {
// given
when(characterRepository.getFellowshipOfTheRing()).thenReturn(fellowshipOfTheRing);
// when
List<Character> heroes = tolkienService.getFellowshipOfTheRing();
// then
assertThat(heroes,
hasItems(new ReflectionEquals(new Character("Frodo",
HOBBIT,
LocalDate.of(2968, Month.SEPTEMBER, 22))),
new ReflectionEquals(new Character("Gandalf", MAIAR, LocalDate.MIN))));
}
项目:jtwig-core
文件:BlockContextTest.java
@Test
public void pollFirstMultiple() {
map.put(IDENTIFIER, blockDefinitionsWithBothNodes);
assertThat(map.get(IDENTIFIER).size(), is(2));
Optional<BlockDefinition> definition1 = underTest.pollFirst(IDENTIFIER);
assertThat(definition1.isPresent(), is(true));
assertThat(definition1.get(), new ReflectionEquals(blockDefinition1));
assertThat(map.get(IDENTIFIER).size(), is(1));
Optional<BlockDefinition> definition2 = underTest.pollFirst(IDENTIFIER);
assertThat(definition2.isPresent(), is(true));
assertThat(definition2.get(), new ReflectionEquals(blockDefinition2));
assertThat(map.get(IDENTIFIER).size(), is(0));
}
项目:elastic-jobx
文件:ExecutionContextServiceTest.java
@Test
public void assertGetJobExecutionShardingContextWhenNotAssignShardingItem() {
when(configService.getShardingTotalCount()).thenReturn(3);
when(configService.isFailover()).thenReturn(false);
when(configService.isMonitorExecution()).thenReturn(false);
when(configService.getFetchDataCount()).thenReturn(10);
JobExecutionMultipleShardingContext expected = new JobExecutionMultipleShardingContext();
expected.setJobName("testJob");
expected.setShardingTotalCount(3);
expected.setFetchDataCount(10);
assertThat(executionContextService.getJobExecutionShardingContext(Collections.<Integer>emptyList()), new ReflectionEquals(expected));
verify(configService).getShardingTotalCount();
verify(configService).isMonitorExecution();
verify(configService).getFetchDataCount();
}
项目:elastic-jobx
文件:ExecutionContextServiceTest.java
@Test
public void assertGetJobExecutionShardingContextWhenAssignShardingItems() {
when(configService.getShardingTotalCount()).thenReturn(3);
when(configService.isFailover()).thenReturn(false);
when(configService.isMonitorExecution()).thenReturn(false);
when(configService.getFetchDataCount()).thenReturn(10);
Map<Integer, String> shardingItemParameters = new HashMap<Integer, String>(3);
shardingItemParameters.put(0, "A");
shardingItemParameters.put(1, "B");
shardingItemParameters.put(2, "C");
when(configService.getShardingItemParameters()).thenReturn(shardingItemParameters);
Map<Integer, String> offsets = new HashMap<Integer, String>(2);
offsets.put(0, "offset0");
offsets.put(1, "offset1");
when(offsetService.getOffsets(Arrays.asList(0, 1))).thenReturn(offsets);
JobExecutionMultipleShardingContext expected = new JobExecutionMultipleShardingContext();
expected.setJobName("testJob");
expected.setShardingTotalCount(3);
expected.setFetchDataCount(10);
expected.setShardingItems(Arrays.asList(0, 1));
expected.getShardingItemParameters().put(0, "A");
expected.getShardingItemParameters().put(1, "B");
expected.setOffsets(offsets);
assertThat(executionContextService.getJobExecutionShardingContext(Arrays.asList(0, 1)), new ReflectionEquals(expected));
verify(configService).getShardingTotalCount();
verify(configService).isMonitorExecution();
verify(configService).getFetchDataCount();
verify(configService).getShardingItemParameters();
verify(offsetService).getOffsets(Arrays.asList(0, 1));
}
项目:elastic-jobx
文件:ExecutionContextServiceTest.java
@Test
public void assertGetJobExecutionShardingContextWhenHasRunningItems() {
when(configService.getShardingTotalCount()).thenReturn(3);
when(configService.isFailover()).thenReturn(true);
when(configService.isMonitorExecution()).thenReturn(true);
when(jobNodeStorage.isJobNodeExisted("execution/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("execution/1/running")).thenReturn(true);
when(configService.getFetchDataCount()).thenReturn(10);
Map<Integer, String> shardingItemParameters = new HashMap<Integer, String>(3);
shardingItemParameters.put(0, "A");
shardingItemParameters.put(1, "B");
shardingItemParameters.put(2, "C");
when(configService.getShardingItemParameters()).thenReturn(shardingItemParameters);
Map<Integer, String> offsets = new HashMap<Integer, String>(1);
offsets.put(0, "offset0");
when(offsetService.getOffsets(Collections.singletonList(0))).thenReturn(offsets);
JobExecutionMultipleShardingContext expected = new JobExecutionMultipleShardingContext();
expected.setJobName("testJob");
expected.setShardingTotalCount(3);
expected.setFetchDataCount(10);
expected.setShardingItems(Collections.singletonList(0));
expected.getShardingItemParameters().put(0, "A");
expected.setMonitorExecution(true);
expected.setOffsets(offsets);
assertThat(executionContextService.getJobExecutionShardingContext(Lists.newArrayList(0, 1)), new ReflectionEquals(expected));
verify(configService).getShardingTotalCount();
verify(configService).isMonitorExecution();
verify(jobNodeStorage).isJobNodeExisted("execution/0/running");
verify(jobNodeStorage).isJobNodeExisted("execution/1/running");
verify(configService).getFetchDataCount();
verify(configService).getShardingItemParameters();
verify(offsetService).getOffsets(Collections.singletonList(0));
}
项目:ElasticJob
文件:ExecutionContextServiceTest.java
@Test
public void assertGetJobExecutionShardingContextWhenNotAssignShardingItem() {
when(configService.getShardingTotalCount()).thenReturn(3);
when(configService.isFailover()).thenReturn(false);
when(configService.isMonitorExecution()).thenReturn(false);
when(configService.getFetchDataCount()).thenReturn(10);
JobExecutionMultipleShardingContext expected = new JobExecutionMultipleShardingContext();
expected.setJobName("testJob");
expected.setShardingTotalCount(3);
expected.setFetchDataCount(10);
assertThat(executionContextService.getJobExecutionShardingContext(Collections.<Integer>emptyList()), new ReflectionEquals(expected));
verify(configService).getShardingTotalCount();
verify(configService).isMonitorExecution();
verify(configService).getFetchDataCount();
}
项目:ElasticJob
文件:ExecutionContextServiceTest.java
@Test
public void assertGetJobExecutionShardingContextWhenAssignShardingItems() {
when(configService.getShardingTotalCount()).thenReturn(3);
when(configService.isFailover()).thenReturn(false);
when(configService.isMonitorExecution()).thenReturn(false);
when(configService.getFetchDataCount()).thenReturn(10);
Map<Integer, String> shardingItemParameters = new HashMap<>(3);
shardingItemParameters.put(0, "A");
shardingItemParameters.put(1, "B");
shardingItemParameters.put(2, "C");
when(configService.getShardingItemParameters()).thenReturn(shardingItemParameters);
Map<Integer, String> offsets = new HashMap<>(2);
offsets.put(0, "offset0");
offsets.put(1, "offset1");
when(offsetService.getOffsets(Arrays.asList(0, 1))).thenReturn(offsets);
JobExecutionMultipleShardingContext expected = new JobExecutionMultipleShardingContext();
expected.setJobName("testJob");
expected.setShardingTotalCount(3);
expected.setFetchDataCount(10);
expected.setShardingItems(Arrays.asList(0, 1));
expected.getShardingItemParameters().put(0, "A");
expected.getShardingItemParameters().put(1, "B");
expected.setOffsets(offsets);
assertThat(executionContextService.getJobExecutionShardingContext(Arrays.asList(0, 1)), new ReflectionEquals(expected));
verify(configService).getShardingTotalCount();
verify(configService).isMonitorExecution();
verify(configService).getFetchDataCount();
verify(configService).getShardingItemParameters();
verify(offsetService).getOffsets(Arrays.asList(0, 1));
}
项目:ElasticJob
文件:ExecutionContextServiceTest.java
@Test
public void assertGetJobExecutionShardingContextWhenHasRunningItems() {
when(configService.getShardingTotalCount()).thenReturn(3);
when(configService.isFailover()).thenReturn(true);
when(configService.isMonitorExecution()).thenReturn(true);
when(jobNodeStorage.isJobNodeExisted("execution/0/running")).thenReturn(false);
when(jobNodeStorage.isJobNodeExisted("execution/1/running")).thenReturn(true);
when(configService.getFetchDataCount()).thenReturn(10);
Map<Integer, String> shardingItemParameters = new HashMap<>(3);
shardingItemParameters.put(0, "A");
shardingItemParameters.put(1, "B");
shardingItemParameters.put(2, "C");
when(configService.getShardingItemParameters()).thenReturn(shardingItemParameters);
Map<Integer, String> offsets = new HashMap<>(1);
offsets.put(0, "offset0");
when(offsetService.getOffsets(Collections.singletonList(0))).thenReturn(offsets);
JobExecutionMultipleShardingContext expected = new JobExecutionMultipleShardingContext();
expected.setJobName("testJob");
expected.setShardingTotalCount(3);
expected.setFetchDataCount(10);
expected.setShardingItems(Collections.singletonList(0));
expected.getShardingItemParameters().put(0, "A");
expected.setMonitorExecution(true);
expected.setOffsets(offsets);
assertThat(executionContextService.getJobExecutionShardingContext(Lists.newArrayList(0, 1)), new ReflectionEquals(expected));
verify(configService).getShardingTotalCount();
verify(configService).isMonitorExecution();
verify(jobNodeStorage).isJobNodeExisted("execution/0/running");
verify(jobNodeStorage).isJobNodeExisted("execution/1/running");
verify(configService).getFetchDataCount();
verify(configService).getShardingItemParameters();
verify(offsetService).getOffsets(Collections.singletonList(0));
}
项目:jtwig-core
文件:BlockContextTest.java
@Test
public void addLastMultiple() throws Exception {
underTest.addLast(blockNode1, resourceReference1);
underTest.addLast(blockNode2, resourceReference2);
assertThat(map.get(IDENTIFIER).get(0), new ReflectionEquals(blockDefinition1));
assertThat(map.get(IDENTIFIER).get(1), new ReflectionEquals(blockDefinition2));
}
项目:jtwig-core
文件:BlockContextTest.java
@Test
public void addFirstMultiple() throws Exception {
underTest.addFirst(blockNode1, resourceReference1);
underTest.addFirst(blockNode2, resourceReference2);
assertThat(map.get(IDENTIFIER).get(1), new ReflectionEquals(blockDefinition1));
assertThat(map.get(IDENTIFIER).get(0), new ReflectionEquals(blockDefinition2));
}
项目:jtwig-core
文件:BlockContextTest.java
@Test
public void get() {
map.put(IDENTIFIER, blockDefinitionsWithNode);
Optional<BlockDefinition> definitionA = underTest.get(IDENTIFIER);
assertThat(definitionA.isPresent(), is(true));
assertThat(definitionA.get(), new ReflectionEquals(blockDefinition1));
Optional<BlockDefinition> definitionB = underTest.get(IDENTIFIER, 0);
assertThat(definitionB.isPresent(), is(true));
assertThat(definitionB.get(), new ReflectionEquals(blockDefinition1));
}
项目:jtwig-core
文件:BlockContextTest.java
@Test
public void getMultiple() {
map.put(IDENTIFIER, blockDefinitionsWithBothNodes);
Optional<BlockDefinition> definition1 = underTest.get(IDENTIFIER, 0);
assertThat(definition1.isPresent(), is(true));
assertThat(definition1.get(), new ReflectionEquals(blockDefinition1));
Optional<BlockDefinition> definition2 = underTest.get(IDENTIFIER, 1);
assertThat(definition2.isPresent(), is(true));
assertThat(definition2.get(), new ReflectionEquals(blockDefinition2));
}
项目:fitbit-bat
文件:FitbitApiCredentialsCacheOdbTest.java
@Test
public void testSaveResourceCredentials() throws Exception {
final APIResourceCredentials credentials1 = new APIResourceCredentials(TestUtils.LOCAL_USER_ID, "tempToken1", "tempTokenSecret1");
final APIResourceCredentials credentials2 = new APIResourceCredentials(TestUtils.LOCAL_USER_ID, "tempToken2", "tempTokenSecret2");
this.fitbitApiCredentialsCacheOdb.saveResourceCredentials(TestUtils.LOCAL_USER_DETAIL, credentials1);
assertTrue(new ReflectionEquals(credentials1).matches(this.fitbitApiCredentialsCacheOdb.getResourceCredentials(TestUtils.LOCAL_USER_DETAIL)));
this.fitbitApiCredentialsCacheOdb.saveResourceCredentials(TestUtils.LOCAL_USER_DETAIL, credentials2);
assertTrue(new ReflectionEquals(credentials2).matches(this.fitbitApiCredentialsCacheOdb.getResourceCredentials(TestUtils.LOCAL_USER_DETAIL)));
}
项目:virtual-schemas
文件:RequestJsonParserTest.java
/**
* Without this method we would need to override equals() and .hashcode() for each object, which explodes code and makes it less maintainable
*/
public <T> void assertObjectEquals(final T expected, final T actual) {
assertTrue("Expected:\n" + expected + "\nactual:\n" + actual, new ReflectionEquals(actual, (String[])null).matches(expected));
}
项目:jtwig-core
文件:BlockContextTest.java
@Test
public void addLast() throws Exception {
underTest.addLast(blockNode1, resourceReference1);
assertThat(map.get(IDENTIFIER).peek(), new ReflectionEquals(blockDefinition1));
}
项目:jtwig-core
文件:BlockContextTest.java
@Test
public void addLastFirst() throws Exception {
underTest.addFirst(blockNode1, resourceReference1);
assertThat(map.get(IDENTIFIER).peek(), new ReflectionEquals(blockDefinition1));
}
项目:fitbit-bat
文件:FitbitApiCredentialsCacheOdbTest.java
@Test
public void testGetResourceCredentials() throws Exception {
assertNull(this.fitbitApiCredentialsCacheOdb.getResourceCredentials(TestUtils.LOCAL_USER_DETAIL));
this.fitbitApiCredentialsCacheOdb.saveResourceCredentials(TestUtils.LOCAL_USER_DETAIL, this.apiResourceCredentials);
assertTrue(new ReflectionEquals(this.apiResourceCredentials).matches(this.fitbitApiCredentialsCacheOdb.getResourceCredentials(TestUtils.LOCAL_USER_DETAIL)));
}
项目:fitbit-bat
文件:FitbitApiCredentialsCacheOdbTest.java
@Test
public void testGetResourceCredentialsByTempToken() throws Exception {
this.fitbitApiCredentialsCacheOdb.saveResourceCredentials(TestUtils.LOCAL_USER_DETAIL, this.apiResourceCredentials);
assertTrue(new ReflectionEquals(this.apiResourceCredentials).matches(this.fitbitApiCredentialsCacheOdb.getResourceCredentialsByTempToken("tempToken")));
}
项目:astor
文件:Matchers.java
/**
* Object argument that is reflection-equal to the given value with support for excluding
* selected fields from a class.
* <p>
* This matcher can be used when equals() is not implemented on compared objects.
* Matcher uses java reflection API to compare fields of wanted and actual object.
* <p>
* Works similarly to EqualsBuilder.reflectionEquals(this, other, exlucdeFields) from
* apache commons library.
* <p>
* <b>Warning</b> The equality check is shallow!
* <p>
* See examples in javadoc for {@link Matchers} class
*
* @param value
* the given value.
* @param excludeFields
* fields to exclude, if field does not exist it is ignored.
* @return <code>null</code>.
*/
public static <T> T refEq(T value, String... excludeFields) {
return reportMatcher(new ReflectionEquals(value, excludeFields)).<T>returnNull();
}
项目:astor
文件:Matchers.java
/**
* Object argument that is reflection-equal to the given value with support for excluding
* selected fields from a class.
* <p>
* This matcher can be used when equals() is not implemented on compared objects.
* Matcher uses java reflection API to compare fields of wanted and actual object.
* <p>
* Works similarly to EqualsBuilder.reflectionEquals(this, other, exlucdeFields) from
* apache commons library.
* <p>
* <b>Warning</b> The equality check is shallow!
* <p>
* See examples in javadoc for {@link Matchers} class
*
* @param value
* the given value.
* @param excludeFields
* fields to exclude, if field does not exist it is ignored.
* @return <code>null</code>.
*/
public static <T> T refEq(T value, String... excludeFields) {
return reportMatcher(new ReflectionEquals(value, excludeFields)).<T>returnNull();
}