本文整理匯總了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