本文整理汇总了Java中org.hamcrest.CoreMatchers类的典型用法代码示例。如果您正苦于以下问题:Java CoreMatchers类的具体用法?Java CoreMatchers怎么用?Java CoreMatchers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CoreMatchers类属于org.hamcrest包,在下文中一共展示了CoreMatchers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startMainActivityFromHomeScreen
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Before
public void startMainActivityFromHomeScreen() {
// Initialize UiDevice instance
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
// Start from the home screen
mDevice.pressHome();
// Wait for launcher
final String launcherPackage = mDevice.getLauncherPackageName();
Assert.assertThat(launcherPackage, CoreMatchers.notNullValue());
mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
LAUNCH_TIMEOUT);
// Launch the app
Context context = InstrumentationRegistry.getContext();
final Intent intent = context.getPackageManager()
.getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE);
// Clear out any previous instances
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);
// Wait for the app to appear
mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)),
LAUNCH_TIMEOUT);
}
示例2: testWindowsShellScriptBuilderEnv
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Test (timeout = 10000)
public void testWindowsShellScriptBuilderEnv() throws IOException {
// Test is only relevant on Windows
Assume.assumeTrue(Shell.WINDOWS);
// The tests are built on assuming 8191 max command line length
assertEquals(8191, Shell.WINDOWS_MAX_SHELL_LENGHT);
ShellScriptBuilder builder = ShellScriptBuilder.create();
// test env
builder.env("somekey", org.apache.commons.lang.StringUtils.repeat("A", 1024));
builder.env("somekey", org.apache.commons.lang.StringUtils.repeat(
"A", Shell.WINDOWS_MAX_SHELL_LENGHT - ("@set somekey=").length()));
try {
builder.env("somekey", org.apache.commons.lang.StringUtils.repeat(
"A", Shell.WINDOWS_MAX_SHELL_LENGHT - ("@set somekey=").length()) + 1);
fail("long env was expected to throw");
} catch(IOException e) {
assertThat(e.getMessage(), CoreMatchers.containsString(expectedMessage));
}
}
示例3: inputTypeFinder_should_returnClassItself
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Test
public void inputTypeFinder_should_returnClassItself() {
//GIVEN
source =
forSourceString(
"test.Test",
"" //
+ "package test;\n" //
+ "import org.gradle.incap.Annotation1;\n" //
+ "@Annotation1\n" //
+ "public class Test {\n" //
+ "}");
//WHEN
InputType inputType = findInputTypeSuccessFully(source);
//THEN
assertThat(inputType, CoreMatchers.notNullValue());
assertThat(inputType.getName(), CoreMatchers.is("test.Test"));
}
示例4: verifyExceptionCaptured
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
/**
* Verify that the given exception event capture (as returned by
* getAndInitExceptionCapture) has thrown an exception of the given
* expectedExceptionClass.
* Resets the capture
* @param err
*/
void verifyExceptionCaptured(
OFMessage err, Class<? extends Throwable> expectedExceptionClass) {
Throwable caughtEx = null;
// This should purposely cause an exception
try{
switchHandler.processOFMessage(err);
}
catch(Exception e){
// Capture the exception
caughtEx = e;
}
assertThat(caughtEx, CoreMatchers.instanceOf(expectedExceptionClass));
}
示例5: inputTypeFinder_should_returnClassContainingField
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Test
public void inputTypeFinder_should_returnClassContainingField() {
//GIVEN
source =
forSourceString(
"test.Test",
"" //
+ "package test;\n" //
+ "import org.gradle.incap.Annotation1;\n" //
+ "public class Test {\n" //
+ " @Annotation1 String foo;\n" //
+ "}");
//WHEN
InputType inputType = findInputTypeSuccessFully(source);
//THEN
assertThat(inputType, CoreMatchers.notNullValue());
assertThat(inputType.getName(), CoreMatchers.is("test.Test"));
}
示例6: waitForInitialRemoteData_mainThreadThrows
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Test
@UiThreadTest
public void waitForInitialRemoteData_mainThreadThrows() {
final SyncUser user = SyncTestUtils.createTestUser(Constants.AUTH_URL);
SyncConfiguration config = new SyncConfiguration.Builder(user, Constants.USER_REALM)
.waitForInitialRemoteData()
.build();
Realm realm = null;
try {
realm = Realm.getInstance(config);
fail();
} catch (IllegalStateException expected) {
assertThat(expected.getMessage(), CoreMatchers.containsString(
"downloadAllServerChanges() cannot be called from the main thread."));
} finally {
if (realm != null) {
realm.close();
}
}
}
示例7: migrationException_realmListChanged
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Test
public void migrationException_realmListChanged() throws IOException {
RealmConfiguration config = configFactory.createConfiguration();
// Initialize the schema with RealmList<Cat>
Realm.getInstance(configFactory.createConfiguration()).close();
DynamicRealm dynamicRealm = DynamicRealm.getInstance(config);
dynamicRealm.beginTransaction();
// Change the RealmList type to RealmList<Dog>
RealmObjectSchema dogSchema = dynamicRealm.getSchema().get(Dog.CLASS_NAME);
RealmObjectSchema ownerSchema = dynamicRealm.getSchema().get(CatOwner.CLASS_NAME);
ownerSchema.removeField(CatOwner.FIELD_CATS);
ownerSchema.addRealmListField(CatOwner.FIELD_CATS, dogSchema);
dynamicRealm.commitTransaction();
dynamicRealm.close();
try {
realm = Realm.getInstance(config);
fail();
} catch (RealmMigrationNeededException ignored) {
assertThat(ignored.getMessage(),
CoreMatchers.containsString("Property 'CatOwner.cats' has been changed from 'array<Dog>' to 'array<Cat>'"));
}
}
示例8: setRequired_true_onPrimaryKeyField_containsNullValues_shouldThrow
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Test
public void setRequired_true_onPrimaryKeyField_containsNullValues_shouldThrow() {
if (type == ObjectSchemaType.IMMUTABLE) {
return;
}
for (PrimaryKeyFieldType fieldType : PrimaryKeyFieldType.values()) {
String className = fieldType.getType().getSimpleName() + "Class";
String fieldName = "primaryKey";
schema = realmSchema.create(className);
if (!fieldType.isNullable()) {
continue;
}
schema.addField(fieldName, fieldType.getType(), FieldAttribute.PRIMARY_KEY);
DynamicRealmObject object = ((DynamicRealm)realm).createObject(schema.getClassName(), null);
assertTrue(object.isNull(fieldName));
try {
schema.setRequired(fieldName, true);
fail();
} catch (IllegalStateException expected) {
assertThat(expected.getMessage(),
CoreMatchers.containsString("The primary key field 'primaryKey' has 'null' values stored."));
}
realmSchema.remove(className);
}
}
示例9: moveToWaitHello
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Test
public void moveToWaitHello() throws Exception {
resetChannel();
channel.write(capture(writeCapture));
expectLastCall().andReturn(null).once();
replay(channel);
// replay unused mocks
replay(messageEvent);
handler.channelConnected(ctx, channelStateEvent);
List<OFMessage> msgs = getMessagesFromCapture();
assertEquals(1, msgs.size());
assertEquals(OFType.HELLO, msgs.get(0).getType());
assertThat(handler.getStateForTesting(), CoreMatchers.instanceOf(OFChannelHandler.WaitHelloState.class));
verifyUniqueXids(msgs);
}
示例10: sameHub
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
/**
* Return the same hub.
* @throws Exception If fails
*/
@Test
public void sameHub() throws Exception {
final Hub hub = new RtHub(
new URI("hub.com"),
"token"
);
MatcherAssert.assertThat(
new RtUsers(
hub
).hub(),
CoreMatchers.equalTo(
hub
)
);
}
示例11: waitForDbCreation
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Before
public void waitForDbCreation() throws Throwable {
final CountDownLatch latch = new CountDownLatch(1);
final LiveData<Boolean> databaseCreated = AppDatabase.getInstance(
InstrumentationRegistry.getTargetContext(), new AppExecutors())
.getDatabaseCreated();
mActivityRule.runOnUiThread(new Runnable() {
@Override
public void run() {
databaseCreated.observeForever(new Observer<Boolean>() {
@Override
public void onChanged(@Nullable Boolean aBoolean) {
if (Boolean.TRUE.equals(aBoolean)) {
databaseCreated.removeObserver(this);
latch.countDown();
}
}
});
}
});
MatcherAssert.assertThat("database should've initialized",
latch.await(1, TimeUnit.MINUTES), CoreMatchers.is(true));
}
示例12: sameUser
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
/**
* Return the same user.
* @throws Exception If fails
*/
@Test
public void sameUser() throws Exception {
final Request req = new JdkRequest("");
final RtUsers users = new RtUsers(
req,
new RtHub(
req
)
);
MatcherAssert.assertThat(
new RtUser(
req,
users,
"me"
).users(),
CoreMatchers.equalTo(
users
)
);
}
示例13: containsTheTypes
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
/**
* Returns a {@link Matcher} that checks if the field contains the provided
* types as a JSON Array.
*
* @param types the types to match
* @return a matcher for a type JSON Array
* @review
*/
public static Matcher<? extends JsonElement> containsTheTypes(
String... types) {
Stream<String> stream = Arrays.stream(types);
List<Matcher<? super JsonElement>> matchers = stream.map(
CoreMatchers::equalTo
).map(
JsonMatchers::aJsonString
).collect(
Collectors.toList()
);
return is(aJsonArrayThat(contains(matchers)));
}
示例14: moveToWaitFeaturesReply
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
/** Move the channel from scratch to WAIT_FEATURES_REPLY state
* Builds on moveToWaitHello()
* adds testing for WAIT_HELLO state
*/
@Test
public void moveToWaitFeaturesReply() throws Exception {
moveToWaitHello();
resetChannel();
channel.write(capture(writeCapture));
expectLastCall().andReturn(null).atLeastOnce();
replay(channel);
OFMessage hello = factory.buildHello().build();
sendMessageToHandlerWithControllerReset(ImmutableList.<OFMessage>of(hello));
List<OFMessage> msgs = getMessagesFromCapture();
assertEquals(1, msgs.size());
assertEquals(OFType.FEATURES_REQUEST, msgs.get(0).getType());
verifyUniqueXids(msgs);
assertThat(handler.getStateForTesting(), CoreMatchers.instanceOf(OFChannelHandler.WaitFeaturesReplyState.class));
}
示例15: testPull_unknownBlob
import org.hamcrest.CoreMatchers; //导入依赖的package包/类
@Test
public void testPull_unknownBlob() throws RegistryException, IOException, DigestException {
DescriptorDigest nonexistentDigest =
DescriptorDigest.fromHash(
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
try {
RegistryClient registryClient = new RegistryClient(null, "localhost:5000", "busybox");
registryClient.pullBlob(nonexistentDigest, Mockito.mock(Path.class));
Assert.fail("Trying to pull nonexistent blob should have errored");
} catch (RegistryErrorException ex) {
Assert.assertThat(
ex.getMessage(),
CoreMatchers.containsString(
"pull BLOB for localhost:5000/busybox with digest " + nonexistentDigest));
}
}
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:19,代码来源:BlobPullerIntegrationTest.java