java类org.hamcrest.core.IsEqual的实例源码

HomeActivityTest.java 文件源码 项目:Cook-E 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Tests swiping to change tabs
 */
public void testTabSwiping() {
    final Matcher<View> mealsTab = withText(R.string.meals);
    final Matcher<View> recipesTab = withText(R.string.recipes);
    final Matcher<View> mealList = withTagKey(R.id.test_tag_meal_list,
            Is.<Object>is("Meal List"));
    final Matcher<View> recipeList = withTagKey(R.id.test_tag_recipe_list,
            Is.<Object>is("Recipe List"));
    final Matcher<View> pager = withClassName(IsEqual.equalTo(ViewPager.class.getName()));

    onView(pager).perform(swipeLeft());
    SystemClock.sleep(SWITCH_DELAY_MS);
    onView(recipesTab).check(matches(isSelected()));
    onView(pager).perform(swipeRight());
    SystemClock.sleep(SWITCH_DELAY_MS);
    onView(mealsTab).check(matches(isSelected()));
}
HadoopReduceCombineFunctionITCase.java 文件源码 项目:flink 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void testCombiner() throws Exception {
    org.junit.Assume.assumeThat(mode, new IsEqual<TestExecutionMode>(TestExecutionMode.CLUSTER));
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

    DataSet<Tuple2<IntWritable, IntWritable>> ds = HadoopTestData.getKVPairDataSet(env).
            map(new Mapper3());

    DataSet<Tuple2<IntWritable, IntWritable>> counts = ds.
            groupBy(0).
            reduceGroup(new HadoopReduceCombineFunction<IntWritable, IntWritable, IntWritable, IntWritable>(
                    new SumReducer(), new KeyChangingReducer()));

    String resultPath = tempFolder.newFile().toURI().toString();

    counts.writeAsText(resultPath);
    env.execute();

    String expected = "(0,5)\n" +
            "(1,6)\n" +
            "(2,5)\n" +
            "(3,5)\n";

    compareResultsByLinesInMemory(expected, resultPath);
}
HadoopReduceCombineFunctionITCase.java 文件源码 项目:flink 阅读 17 收藏 0 点赞 0 评论 0
@Test
public void testCombiner() throws Exception {
    org.junit.Assume.assumeThat(mode, new IsEqual<TestExecutionMode>(TestExecutionMode.CLUSTER));
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

    DataSet<Tuple2<IntWritable, IntWritable>> ds = HadoopTestData.getKVPairDataSet(env).
            map(new Mapper3());

    DataSet<Tuple2<IntWritable, IntWritable>> counts = ds.
            groupBy(0).
            reduceGroup(new HadoopReduceCombineFunction<IntWritable, IntWritable, IntWritable, IntWritable>(
                    new SumReducer(), new KeyChangingReducer()));

    String resultPath = tempFolder.newFile().toURI().toString();

    counts.writeAsText(resultPath);
    env.execute();

    String expected = "(0,5)\n"+
            "(1,6)\n" +
            "(2,5)\n" +
            "(3,5)\n";

    compareResultsByLinesInMemory(expected, resultPath);
}
PermissionServiceTest.java 文件源码 项目:credhub 阅读 16 收藏 0 点赞 0 评论 0
@Test
public void getAccessControlList_delegatesToDataService() {
  when(permissionCheckingService.hasPermission(USER_NAME, CREDENTIAL_NAME, PermissionOperation.READ_ACL))
      .thenReturn(false);
  List<PermissionEntry> expectedPermissionEntries = newArrayList();
  when(permissionDataService.getPermissions(expectedCredential))
      .thenReturn(expectedPermissionEntries);

  try {
    subject.getPermissions(expectedCredentialVersion, auditRecordParameters, CREDENTIAL_NAME);
  } catch (EntryNotFoundException e) {
    assertThat(e.getMessage(), IsEqual.equalTo("error.credential.invalid_access"));
    assertThat(auditRecordParameters.size(), IsEqual.equalTo(1));
    assertThat(auditRecordParameters.get(0).getCredentialName(), IsEqual.equalTo(CREDENTIAL_NAME));
    assertThat(auditRecordParameters.get(0).getAuditingOperationCode(), IsEqual.equalTo(ACL_ACCESS));
  }
}
PermissionServiceTest.java 文件源码 项目:credhub 阅读 16 收藏 0 点赞 0 评论 0
@Test
public void deleteAccessControlEntry_whenTheUserLacksPermission_throwsAnException() {
  when(permissionCheckingService.hasPermission(userContext.getActor(), CREDENTIAL_NAME, PermissionOperation.WRITE_ACL))
      .thenReturn(false);
  when(permissionDataService.deletePermissions(CREDENTIAL_NAME, "other-actor"))
      .thenReturn(true);
  try {
    subject.deletePermissions(CREDENTIAL_NAME, "other-actor", auditRecordParameters);
    fail("should throw");
  } catch (EntryNotFoundException e) {
    assertThat(e.getMessage(), IsEqual.equalTo("error.credential.invalid_access"));
    assertThat(auditRecordParameters.size(), equalTo(1));
    assertThat(auditRecordParameters.get(0).getCredentialName(), equalTo(CREDENTIAL_NAME));
    assertThat(auditRecordParameters.get(0).getAuditingOperationCode(), equalTo(ACL_DELETE));
  }
}
PermissionServiceTest.java 文件源码 项目:credhub 阅读 18 收藏 0 点赞 0 评论 0
@Test
public void deleteAccessControlEntry_whenTheUserIsTheSameAsActor_throwsAnException() {
  when(permissionCheckingService.hasPermission(userContext.getActor(), CREDENTIAL_NAME, PermissionOperation.WRITE_ACL))
      .thenReturn(true);
  when(permissionDataService.deletePermissions(CREDENTIAL_NAME, userContext.getActor()))
      .thenReturn(true);
  try {
    subject.deletePermissions(CREDENTIAL_NAME, userContext.getActor(), auditRecordParameters);
    fail("should throw");
  } catch (InvalidPermissionOperationException iaoe) {
    assertThat(iaoe.getMessage(), IsEqual.equalTo("error.permission.invalid_update_operation"));
    assertThat(auditRecordParameters.size(), equalTo(1));
    assertThat(auditRecordParameters.get(0).getCredentialName(), equalTo(CREDENTIAL_NAME));
    assertThat(auditRecordParameters.get(0).getAuditingOperationCode(), equalTo(ACL_DELETE));
  }
}
Ed25519DsaSignerTest.java 文件源码 项目:nem.core 阅读 16 收藏 0 点赞 0 评论 0
@Test
public void verifyReturnsFalseIfPublicKeyIsZeroArray() {
    // Arrange:
    final CryptoEngine engine = this.getCryptoEngine();
    final KeyPair kp = KeyPair.random(engine);
    final DsaSigner dsaSigner = this.getDsaSigner(kp);
    final byte[] input = org.nem.core.test.Utils.generateRandomBytes();
    final Signature signature = dsaSigner.sign(input);
    final Ed25519DsaSigner dsaSignerWithZeroArrayPublicKey = Mockito.mock(Ed25519DsaSigner.class);
    final KeyPair keyPairWithZeroArrayPublicKey = Mockito.mock(KeyPair.class);
    Mockito.when(dsaSignerWithZeroArrayPublicKey.getKeyPair())
            .thenReturn(keyPairWithZeroArrayPublicKey);
    Mockito.when(keyPairWithZeroArrayPublicKey.getPublicKey())
            .thenReturn(new PublicKey(new byte[32]));
    Mockito.when(dsaSignerWithZeroArrayPublicKey.verify(input, signature)).thenCallRealMethod();
    Mockito.when(dsaSignerWithZeroArrayPublicKey.isCanonicalSignature(signature)).thenReturn(true);

    // Act:
    final boolean result = dsaSignerWithZeroArrayPublicKey.verify(input, signature);

    // Assert (getKeyPair() would be called more than once if it got beyond the second check):
    Assert.assertThat(result, IsEqual.equalTo(false));
    Mockito.verify(dsaSignerWithZeroArrayPublicKey, Mockito.times(1)).isCanonicalSignature(signature);
    Mockito.verify(dsaSignerWithZeroArrayPublicKey, Mockito.times(1)).getKeyPair();
}
NetworkInfoTest.java 文件源码 项目:nem.core 阅读 16 收藏 0 点赞 0 评论 0
@Test
public void isCompatibleOnlyReturnsTrueForCompatibleAddresses() {
    // Arrange:
    final Map<String, Address> descToAddressMap = new HashMap<String, Address>() {
        {
            this.put("NON_BASE32_CHARS", Address.fromEncoded("TAAAAAAAAAA1BBBBBBBBBCCCCCCCCCCDDDDDDDDD"));
            this.put("UNKNOWN_NETWORK", Address.fromEncoded("YAAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDD"));
            this.put("COMPATIBLE", Address.fromEncoded("ZAAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDD"));
            this.put("NON_COMPATIBLE", Address.fromEncoded("NAAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDD"));
        }
    };

    final NetworkInfo info = new NetworkInfo((byte)0xC8, 'Z', createNemesisBlockInfo());

    // Assert:
    Assert.assertThat(info.isCompatible(descToAddressMap.get("NON_BASE32_CHARS")), IsEqual.equalTo(false));
    Assert.assertThat(info.isCompatible(descToAddressMap.get("UNKNOWN_NETWORK")), IsEqual.equalTo(false));
    Assert.assertThat(info.isCompatible(descToAddressMap.get("COMPATIBLE")), IsEqual.equalTo(true));
    Assert.assertThat(info.isCompatible(descToAddressMap.get("NON_COMPATIBLE")), IsEqual.equalTo(false));
}
JarFacadeTest.java 文件源码 项目:nem.core 阅读 16 收藏 0 点赞 0 评论 0
private static void assertValidNemVendorName(final String name) throws IOException {
    // Arrange:
    final Manifest manifest = new Manifest();
    final Attributes attributes = manifest.getMainAttributes();
    attributes.putValue("Manifest-Version", "1.0");
    attributes.putValue("Implementation-Vendor", name);
    attributes.putValue("Implementation-Version", "test-version");
    attributes.putValue("Implementation-Title", "test-title");

    final byte[] bytes = MetaDataTestUtils.createJarBytes(manifest);
    try (final InputStream inputStream = new ByteArrayInputStream(bytes)) {
        final URL url = MetaDataTestUtils.createMockUrl("file://path/nem.jar", inputStream);
        final JarFacade facade = new JarFacade(url);

        // Assert:
        Assert.assertThat(facade.getName(), IsEqual.equalTo("nem.jar"));
        Assert.assertThat(facade.isWebStart(), IsEqual.equalTo(false));
        Assert.assertThat(facade.getVersion(), IsEqual.equalTo("test-version"));
        Assert.assertThat(facade.getTitle(), IsEqual.equalTo("test-title"));
    }
}
AsyncTimerTest.java 文件源码 项目:nem.core 阅读 14 收藏 0 点赞 0 评论 0
@Test
public void initialDelayIsRespected() throws InterruptedException {
    // Arrange:
    final CountableFuture cf = new CountableFuture();
    try (final AsyncTimer timer = createTimer(cf, TIME_UNIT, 10 * TIME_UNIT)) {
        // Arrange:
        Thread.sleep(TIME_HALF_UNIT);

        // Assert:
        Assert.assertThat(cf.getNumCalls(), IsEqual.equalTo(0));

        // Arrange:
        Thread.sleep(3 * TIME_HALF_UNIT);

        // Assert:
        Assert.assertThat(cf.getNumCalls(), IsEqual.equalTo(1));
        Assert.assertThat(timer.isStopped(), IsEqual.equalTo(false));
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号