本文整理汇总了Java中org.hamcrest.core.StringContains类的典型用法代码示例。如果您正苦于以下问题:Java StringContains类的具体用法?Java StringContains怎么用?Java StringContains使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringContains类属于org.hamcrest.core包,在下文中一共展示了StringContains类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertAndSendCustomJmsMessageConverter
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void convertAndSendCustomJmsMessageConverter() throws JMSException {
messagingTemplate.setJmsMessageConverter(new SimpleMessageConverter() {
@Override
public javax.jms.Message toMessage(Object object, Session session)
throws JMSException, org.springframework.jms.support.converter.MessageConversionException {
throw new org.springframework.jms.support.converter.MessageConversionException("Test exception");
}
});
messagingTemplate.convertAndSend("myQueue", "msg to convert");
verify(jmsTemplate).send(eq("myQueue"), messageCreator.capture());
thrown.expect(org.springframework.messaging.converter.MessageConversionException.class);
thrown.expectMessage(new StringContains("Test exception"));
messageCreator.getValue().createMessage(mock(Session.class));
}
示例2: missingJiraUrl
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void missingJiraUrl() throws IOException, ScmSyncException {
Properties props = new Properties();
props.setProperty("port","31");
props.setProperty("allowed.hosts", "127.0.0.1,192.168.1.1");
props.setProperty("jira.user", "user");
props.setProperty("jira.password", "password");
writePropertiesFile(props, Server.propertiesFileName);
// Set runtime environment
System.setProperty(Server.homeDirProperty, testDir.getAbsolutePath());
expectedException.expect(ScmSyncException.class);
expectedException.expectMessage(new StringContains("jira.url property missing from"));
new Server();
}
示例3: missingAllowedList
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void missingAllowedList() throws Exception {
// Configure Partial Properties File
Properties props = new Properties();
props.setProperty("port","31");
File propFile = writePropertiesFile(props, Server.propertiesFileName);
// Set runtime environment
System.setProperty(Server.homeDirProperty, testDir.getAbsolutePath());
// configure expected error
expectedException.expect(ScmSyncException.class);
expectedException.expectMessage(new StringContains("Cannot locate allowed.hosts property in scmsync properties"));
new Server();
}
示例4: testAddFriend
import org.hamcrest.core.StringContains; //导入依赖的package包/类
/**
* US02.01.01, UC02.02.01
*/
@Test
public void testAddFriend() throws Exception {
onView(withId(R.id.addFriendFab)).perform(click());
pause();
onView(withClassName(new StringContains("EditText"))).
perform(typeText(TEST_OTHER_USER),
closeSoftKeyboard());
pause();
onView(withText("Add")).
perform(click());
pause();
onData(hasToString(TEST_OTHER_USER))
.inAdapterView(withId(R.id.friendsListListView))
.check(matches(isDisplayed()));
pause();
}
示例5: testAddAndRemoveFriend
import org.hamcrest.core.StringContains; //导入依赖的package包/类
/**
* UC02.03.01
*/
@Test
public void testAddAndRemoveFriend() throws InterruptedException {
onView(withId(R.id.addFriendFab)).perform(click());
pause();
onView(withClassName(new StringContains("EditText")))
.perform(typeText(TEST_OTHER_USER),
closeSoftKeyboard());
pause();
onView(withText("Add"))
.perform(click());
pause();
onData(hasToString(TEST_OTHER_USER))
.inAdapterView(withId(R.id.friendsListListView))
.check(matches(isDisplayed()));
pause();
onData(hasToString(TEST_OTHER_USER))
.inAdapterView(withId(R.id.friendsListListView))
.perform(longClick());
pause();
onView(withId(R.id.friendsListListView))
.check(matches(not(withAdaptedData(hasToString(TEST_OTHER_USER)))));
pause();
}
示例6: testEncodeDeclaredExtensionWithAddressContent
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void testEncodeDeclaredExtensionWithAddressContent() {
IParser parser = new FhirContext().newJsonParser();
MyPatientWithOneDeclaredAddressExtension patient = new MyPatientWithOneDeclaredAddressExtension();
patient.addAddress().setUse(AddressUse.HOME);
patient.setFoo(new Address().addLine("line1"));
String val = parser.encodeResourceToString(patient);
ourLog.info(val);
assertThat(val, StringContains.containsString("\"extension\":[{\"url\":\"urn:foo\",\"valueAddress\":{\"line\":[\"line1\"]}}]"));
MyPatientWithOneDeclaredAddressExtension actual = parser.parseResource(MyPatientWithOneDeclaredAddressExtension.class, val);
assertEquals(AddressUse.HOME, patient.getAddress().get(0).getUse());
Address ref = actual.getFoo();
assertEquals("line1", ref.getLine().get(0).getValue());
}
示例7: testAddFriend_emptyInput
import org.hamcrest.core.StringContains; //导入依赖的package包/类
/**
* US02.01.01, UC02.02.01
*/
@Test
public void testAddFriend_emptyInput() {
onView(withId(R.id.addFriendFab)).perform(click());
pause();
onView(withClassName(new StringContains("EditText")))
.perform(clearText(),
closeSoftKeyboard());
pause();
onView(withText("Add"))
.perform(click());
//assert list does not contain friend
onView(withId(R.id.friendsListListView))
.check(matches(not(withAdaptedData(hasToString(PrimaryUserHelper.FRIEND_WITH_AN_INVENTORY)))));
pause();
}
示例8: testEncodeResourceRef
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void testEncodeResourceRef() throws DataFormatException {
Patient patient = new Patient();
patient.setManagingOrganization(new Reference());
IParser p = new FhirContext().newJsonParser();
String str = p.encodeResourceToString(patient);
assertThat(str, IsNot.not(StringContains.containsString("managingOrganization")));
patient.setManagingOrganization(new Reference("Organization/123"));
str = p.encodeResourceToString(patient);
assertThat(str, StringContains.containsString("\"managingOrganization\":{\"reference\":\"Organization/123\"}"));
Organization org = new Organization();
org.addIdentifier().setSystem("foo").setValue("bar");
patient.setManagingOrganization(new Reference(org));
str = p.encodeResourceToString(patient);
assertThat(str, StringContains.containsString("\"contained\":[{\"resourceType\":\"Organization\""));
}
示例9: testDFSWithInvalidCommmand
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void testDFSWithInvalidCommmand() throws Throwable {
FsShell shell = new FsShell(new Configuration());
try (GenericTestUtils.SystemErrCapturer capture =
new GenericTestUtils.SystemErrCapturer()) {
ToolRunner.run(shell, new String[]{"dfs -mkdirs"});
Assert.assertThat("FSShell dfs command did not print the error " +
"message when invalid command is passed",
capture.getOutput(), StringContains.containsString(
"-mkdirs: Unknown command"));
Assert.assertThat("FSShell dfs command did not print help " +
"message when invalid command is passed",
capture.getOutput(), StringContains.containsString(
"Usage: hadoop fs [generic options]"));
}
}
示例10: testExceptionNullMessage
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void testExceptionNullMessage() throws Exception {
final String cmdName = "-cmdExNullMsg";
final Command cmd = Mockito.mock(Command.class);
Mockito.when(cmd.run(Mockito.<String>anyVararg())).thenThrow(
new IllegalArgumentException());
Mockito.when(cmd.getUsage()).thenReturn(cmdName);
final CommandFactory cmdFactory = Mockito.mock(CommandFactory.class);
final String[] names = {cmdName};
Mockito.when(cmdFactory.getNames()).thenReturn(names);
Mockito.when(cmdFactory.getInstance(cmdName)).thenReturn(cmd);
FsShell shell = new FsShell(new Configuration());
shell.commandFactory = cmdFactory;
try (GenericTestUtils.SystemErrCapturer capture =
new GenericTestUtils.SystemErrCapturer()) {
ToolRunner.run(shell, new String[]{cmdName});
Assert.assertThat(capture.getOutput(),
StringContains.containsString(cmdName
+ ": Null exception message"));
}
}
示例11: testEncodeBundleCategory
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void testEncodeBundleCategory() {
Bundle b = new Bundle();
BundleEntryComponent e = b.addEntry();
e.setResource(new Patient());
e.getResource().getMeta().addTag().setSystem("scheme").setCode( "term").setDisplay( "label");
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b);
ourLog.info(val);
assertThat(val, StringContains.containsString("<category term=\"term\" label=\"label\" scheme=\"scheme\"/>"));
b = ourCtx.newXmlParser().parseResource(Bundle.class, val);
assertEquals(1, b.getEntry().size());
assertEquals(1, b.getEntry().get(0).getResource().getMeta().getTag().size());
assertEquals("scheme", b.getEntry().get(0).getResource().getMeta().getTag().get(0).getSystem());
assertEquals("term", b.getEntry().get(0).getResource().getMeta().getTag().get(0).getCode());
assertEquals("label", b.getEntry().get(0).getResource().getMeta().getTag().get(0).getDisplay());
assertNull(b.getEntry().get(0).getResource());
}
示例12: testEncodeExtensionWithResourceContent
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void testEncodeExtensionWithResourceContent() {
IParser parser = new FhirContext().newJsonParser();
Patient patient = new Patient();
patient.addAddress().setUse(AddressUse.HOME);
patient.addExtension().setUrl("urn:foo").setValue( new Reference("Organization/123"));
String val = parser.encodeResourceToString(patient);
ourLog.info(val);
assertThat(val, StringContains.containsString("\"extension\":[{\"url\":\"urn:foo\",\"valueResource\":{\"reference\":\"Organization/123\"}}]"));
Patient actual = parser.parseResource(Patient.class, val);
assertEquals(AddressUse.HOME, patient.getAddress().get(0).getUse());
List<Extension> ext = actual.getExtension();
assertEquals(1, ext.size());
Reference ref = (Reference) ext.get(0).getValue();
assertEquals("Organization/123", ref.getReference());
}
示例13: testOutOfBoundsDate
import org.hamcrest.core.StringContains; //导入依赖的package包/类
/**
* See issue #50
*/
@Test
public void testOutOfBoundsDate() {
Patient p = new Patient();
p.setBirthDate(new DateTimeDt("2000-15-31"));
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
ourLog.info(encoded);
assertThat(encoded, StringContains.containsString("2000-15-31"));
p = ourCtx.newXmlParser().parseResource(Patient.class, encoded);
assertEquals("2000-15-31", p.getBirthDate().getValueAsString());
assertEquals("2001-03-31", new SimpleDateFormat("yyyy-MM-dd").format(p.getBirthDate().getValue()));
ValidationResult result = ourCtx.newValidator().validateWithResult(p);
String resultString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result.getOperationOutcome());
ourLog.info(resultString);
assertEquals(2, result.getOperationOutcome().getIssue().size());
assertThat(resultString, StringContains.containsString("cvc-datatype-valid.1.2.3"));
}
示例14: testEncodeBundleCategory
import org.hamcrest.core.StringContains; //导入依赖的package包/类
@Test
public void testEncodeBundleCategory() {
Bundle b = new Bundle();
BundleEntry e = b.addEntry();
e.setResource(new Patient());
e.addCategory("scheme", "term", "label");
String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeBundleToString(b);
ourLog.info(val);
assertThat(val, StringContains.containsString("<category term=\"term\" label=\"label\" scheme=\"scheme\"/>"));
b = ourCtx.newXmlParser().parseBundle(val);
assertEquals(1, b.getEntries().size());
assertEquals(1, b.getEntries().get(0).getCategories().size());
assertEquals("term", b.getEntries().get(0).getCategories().get(0).getTerm());
assertEquals("label", b.getEntries().get(0).getCategories().get(0).getLabel());
assertEquals("scheme", b.getEntries().get(0).getCategories().get(0).getScheme());
assertNull(b.getEntries().get(0).getResource());
}
示例15: testOutOfBoundsDate
import org.hamcrest.core.StringContains; //导入依赖的package包/类
/**
* See issue #50
*/
@Test
public void testOutOfBoundsDate() {
Patient p = new Patient();
p.setBirthDate(new DateDt("2000-15-31"));
String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p);
ourLog.info(encoded);
assertThat(encoded, StringContains.containsString("2000-15-31"));
p = ourCtx.newXmlParser().parseResource(Patient.class, encoded);
assertEquals("2000-15-31", p.getBirthDateElement().getValueAsString());
assertEquals("2001-03-31", new SimpleDateFormat("yyyy-MM-dd").format(p.getBirthDate()));
ValidationResult result = ourCtx.newValidator().validateWithResult(p);
String resultString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result.getOperationOutcome());
ourLog.info(resultString);
assertEquals(2, result.getOperationOutcome().getIssue().size());
assertThat(resultString, StringContains.containsString("cvc-pattern-valid: Value '2000-15-31'"));
}