本文整理汇总了Java中org.hamcrest.core.IsAnything类的典型用法代码示例。如果您正苦于以下问题:Java IsAnything类的具体用法?Java IsAnything怎么用?Java IsAnything使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IsAnything类属于org.hamcrest.core包,在下文中一共展示了IsAnything类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: answersConditionally
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
/**
* MkContainer can return certain answers for matching conditions.
* @throws Exception If something goes wrong inside.
*/
@Test
public void answersConditionally() throws Exception {
final String match = "matching";
final String mismatch = "not matching";
try (final MkContainer container = new MkGrizzlyContainer()) {
container.next(
new MkAnswer.Simple(mismatch),
Matchers.not(new IsAnything<MkQuery>())
).next(new MkAnswer.Simple(match), new IsAnything<MkQuery>())
.start();
new JdkRequest(container.home())
.through(VerboseWire.class)
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.assertBody(
Matchers.allOf(
Matchers.is(match),
Matchers.not(mismatch)
)
);
}
}
示例2: canAnswerMultipleTimes
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
/**
* MkContainer can answer multiple times for matching requests.
* @throws Exception If something goes wrong inside
*/
@Test
public void canAnswerMultipleTimes() throws Exception {
final String body = "multiple";
final int times = 5;
try (final MkContainer container = new MkGrizzlyContainer()) {
container.next(
new MkAnswer.Simple(body),
new IsAnything<MkQuery>(),
times
).start();
final Request req = new JdkRequest(container.home())
.through(VerboseWire.class);
for (int idx = 0; idx < times; idx += 1) {
req.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.assertBody(Matchers.is(body));
}
}
}
示例3: prioritizesMatchingAnswers
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
/**
* MkContainer can prioritize multiple matching answers by using the
* first matching request.
* @throws Exception If something goes wrong inside.
*/
@Test
public void prioritizesMatchingAnswers() throws Exception {
final String first = "first";
final String second = "second";
try (final MkContainer container = new MkGrizzlyContainer()) {
container
.next(new MkAnswer.Simple(first), new IsAnything<MkQuery>())
.next(new MkAnswer.Simple(second), new IsAnything<MkQuery>())
.start();
new JdkRequest(container.home())
.through(VerboseWire.class)
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.assertBody(
Matchers.allOf(
Matchers.is(first),
Matchers.not(second)
)
);
}
}
示例4: getExtractionResultReturnCorrectEntities
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Test
public void getExtractionResultReturnCorrectEntities() {
// GIVEN
String fixture1 = "Fixture1";
Integer fixture2 = 2;
MappingFixture mappingFixture = new MappingFixture(fixture1, fixture2)
.addExtractorMatcher(ExtractorMatcher.create(new IsAnything()));
// WHEN
ExtractionResult extractionResult = mappingFixture.getExtractionResult();
// THEN
assertThat(extractionResult.getEntities()).containsOnly(fixture1, fixture2);
}
示例5: testTransform
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Test
public void testTransform() throws NoSuchFieldException {
// GIVEN
XlsxFileFixture xlsxFileFixture = new XlsxFileFixture("classpath:tests/fixtures/xlsx-fixture.xlsx");
xlsxFileFixture.addExtractorMatcher(ExtractorMatcher.create(new IsAnything()));
xlsxFileFixture.setFilter(new Filter() {
@Override
public boolean filter(Object entity) {
return false;
}
});
// WHEN
ObjectFixture transformedFixture = xlsxFileFixtureTransformer.transform(xlsxFileFixture);
// THEN
assertCorrectCartEntry(xlsxFileFixture, transformedFixture);
}
示例6: testTransform
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Test
public void testTransform() throws NoSuchFieldException {
// GIVEN
XmlFileFixture xmlFileFixture = new XmlFileFixture("classpath:tests/fixtures/xml-fixture.xml");
xmlFileFixture.addExtractorMatcher(ExtractorMatcher.create(new IsAnything()));
xmlFileFixture.setFilter(new Filter() {
@Override
public boolean filter(Object entity) {
return false;
}
});
// WHEN
ObjectFixture transformedFixture = xmlFileFixtureTransformer.transform(xmlFileFixture);
// THEN
assertCorrectCartEntry(xmlFileFixture, transformedFixture);
}
示例7: testTransform
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Test
public void testTransform() throws NoSuchFieldException {
// GIVEN
SpringFixture springFixture = new SpringFixture("classpath:/tests/fixtures/spring-fixture.xml", User.class);
springFixture.addExtractorMatcher(ExtractorMatcher.create(new IsAnything()));
springFixture.setFilter(new Filter() {
@Override
public boolean filter(Object entity) {
return false;
}
});
// WHEN
ObjectFixture transformedFixture = springFixtureTransformer.transform(springFixture);
// THEN
assertThat(transformedFixture).isInstanceOf(Fixture.class);
assertThat(transformedFixture.getObjects()).hasSize(1);
assertThat(transformedFixture.getObjects().get(0)).isInstanceOf(User.class);
assertThat(springFixture.getExtractionResult().getEntities()).hasSize(1);
assertThat(FilterableFixtureProxy.get(transformedFixture).filter("")).isFalse();
}
示例8: testTransform
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Test
public void testTransform() throws NoSuchFieldException {
// GIVEN
XlsFileFixture xlsFileFixture = new XlsFileFixture("classpath:tests/fixtures/xls-fixture.xls");
xlsFileFixture.addExtractorMatcher(ExtractorMatcher.create(new IsAnything()));
xlsFileFixture.setFilter(new Filter() {
@Override
public boolean filter(Object entity) {
return false;
}
});
// WHEN
ObjectFixture transformedFixture = xlsFileFixtureTransformer.transform(xlsFileFixture);
// THEN
assertCorrectCartEntry(xlsFileFixture, transformedFixture);
}
示例9: getExtractionResultReturnCorrectEntities
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Test
public void getExtractionResultReturnCorrectEntities() {
// GIVEN
generatedFixture //
.addGenerators( //
GeneratedFixture.from(new Product()) //
.addFieldGenerator("id", FieldGenerators.in("1", "2")) //
) //
.addExtractorMatcher(ExtractorMatcher.create("name", new IsAnything())) //
.start();
// WHEN
while (generatedFixture.hasNext()) {
generatedFixture.next();
}
// THEN
assertThat(generatedFixture.getExtractionResult().getEntities()).hasSize(2);
}
示例10: getExtractionResultReturnCorrectEntities
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Test
public void getExtractionResultReturnCorrectEntities() throws IOException {
// GIVEN
File file = folder.newFile("foo.txt");
FileUtils.writeStringToFile(file, "someContent");
String filePath = file.getAbsoluteFile().getAbsolutePath();
FileFixture fileFixture = buildFixture(filePath);
fileFixture.addExtractorMatcher(ExtractorMatcher.create(new IsAnything()));
fileFixture.populateExtractionResult(Arrays.<Object>asList("string1", "string2"));
// WHEN
ExtractionResult extractionResult = fileFixture.getExtractionResult();
// THEN
assertThat(extractionResult.getEntities()).containsOnly("string1", "string2");
}
示例11: returnsErrorIfNoMatches
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
/**
* MkContainer returns HTTP 500 if no answers match.
* @throws Exception If something goes wrong inside
*/
@Test(expected = NoSuchElementException.class)
public void returnsErrorIfNoMatches() throws Exception {
try (final MkContainer container = new MkGrizzlyContainer()) {
container.next(
new MkAnswer.Simple("not supposed to match"),
Matchers.not(new IsAnything<MkQuery>())
).start();
new JdkRequest(container.home())
.through(VerboseWire.class)
.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_INTERNAL_ERROR);
container.take();
}
}
示例12: cachesGetRequest
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
/**
* LastModifiedCachingWire can cache GET requests.
* @throws Exception If fails
*/
@Test
public void cachesGetRequest() throws Exception {
final Map<String, String> headers = Collections.singletonMap(
HttpHeaders.LAST_MODIFIED,
"Wed, 15 Nov 1995 04:58:08 GMT"
);
final MkContainer container = new MkGrizzlyContainer()
.next(
new MkAnswer.Simple(
HttpURLConnection.HTTP_OK,
headers.entrySet(),
LastModifiedCachingWireTest.BODY.getBytes()
)
)
.next(
new MkAnswer.Simple(HttpURLConnection.HTTP_NOT_MODIFIED),
new IsAnything<MkQuery>(),
Tv.TEN
).start();
try {
final Request req = new JdkRequest(container.home())
.through(LastModifiedCachingWire.class);
for (int idx = 0; idx < Tv.TEN; ++idx) {
req.fetch().as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.assertBody(
Matchers.equalTo(LastModifiedCachingWireTest.BODY)
);
}
MatcherAssert.assertThat(
container.queries(), Matchers.equalTo(Tv.TEN)
);
} finally {
container.stop();
}
}
示例13: functionMatcherOnUpperAndLowerFunctions
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Test
public void functionMatcherOnUpperAndLowerFunctions() {
sqlWithFunctions = "SELECT UPPER(foo), LOWER(bar) FROM MyTable";
statementWithFunctions = getParseTree(sqlWithFunctions);
assertThat(statementWithFunctions, hasInQuery(result(upper(new IsAnything<QueryTreeNode>()))));
assertThat(statementWithFunctions, hasInQuery(result(upper(column("foo")))));
assertThat(statementWithFunctions, hasInQuery(result(lower(column("bar")))));
//no such column
assertThat(statementWithFunctions, not(hasInQuery(where(lower(column("barry"))))));
}
示例14: getExtractionResultReturnCorrectEntities
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Test
public void getExtractionResultReturnCorrectEntities() {
// GIVEN
SpringFixture springFixture = new SpringFixture("context", Arrays.<Class<?>>asList(String.class, Integer.class));
springFixture.addExtractorMatcher(ExtractorMatcher.create(new IsAnything()));
springFixture.populateExtractionResult(Arrays.<Object>asList("string1", "string2"));
// WHEN
ExtractionResult extractionResult = springFixture.getExtractionResult();
// THEN
assertThat(extractionResult.getEntities()).containsOnly("string1", "string2");
}
示例15: getConstraints
import org.hamcrest.core.IsAnything; //导入依赖的package包/类
@Override
public Matcher<View> getConstraints() {
return new IsAnything<>();
}