Java 类org.hamcrest.core.IsAnything 实例源码

项目:jcabi-http    文件:MkContainerTest.java   
/**
 * 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)
                )
            );
    }
}
项目:jcabi-http    文件:MkContainerTest.java   
/**
 * 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));
        }
    }
}
项目:jcabi-http    文件:MkContainerTest.java   
/**
 * 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)
                )
            );
    }
}
项目:jixture    文件:TestMappingFixture.java   
@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);
}
项目:jixture    文件:TestXlsxFileFixtureTransformer.java   
@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);
}
项目:jixture    文件:TestXmlFileFixtureTransformer.java   
@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);
}
项目:jixture    文件:TestSpringFixtureTransformer.java   
@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();
}
项目:jixture    文件:TestXlsFileFixtureTransformer.java   
@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);
}
项目:jixture    文件:TestGeneratedFixture.java   
@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);
}
项目:jixture    文件:TestFileFixture.java   
@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");
}
项目:jcabi-http    文件:MkContainerTest.java   
/**
 * 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();
    }
}
项目:jcabi-http    文件:LastModifiedCachingWireTest.java   
/**
 * 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();
    }
}
项目:hamcrest-sql    文件:QueryMatcherTest.java   
@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"))))));
}
项目:jixture    文件:TestSpringFixture.java   
@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");
}
项目:PXLSRT    文件:CameraViewTest.java   
@Override
public Matcher<View> getConstraints() {
    return new IsAnything<>();
}
项目:SimpleCamera    文件:CameraViewTest.java   
@Override
public Matcher<View> getConstraints() {
    return new IsAnything<>();
}
项目:cameraview    文件:CameraViewTest.java   
@Override
public Matcher<View> getConstraints() {
    return new IsAnything<>();
}
项目:jcabi-http    文件:MkGrizzlyContainer.java   
@Override
public MkContainer next(final MkAnswer answer) {
    return this.next(answer, new IsAnything<MkQuery>());
}
项目:mapper    文件:AsyncMatchers.java   
public static <T> Matcher<Async<T>> succeeded() {
  return result(new IsAnything<T>());
}
项目:mapper    文件:AsyncMatchers.java   
public static Matcher<Async<?>> failed() {
  return failure(new IsAnything<>());
}
项目:hamcrest-sql    文件:CaseStatementMatcher.java   
/**
 * Syntactic sugar! This version only checks the content of a conditional in a WHEN clause, such as
 * CASE WHEN (my_id=35)
 *
 * For example, assertThat(query, cased(column("my_id").equals(35)));
 */
@Factory
public static Matcher<QueryTreeNode> cased(Matcher<QueryTreeNode> whenMatcher) {
    return new CaseStatementMatcher(whenMatcher, new IsAnything<QueryTreeNode>(), new IsAnything<QueryTreeNode>());
}
项目:hamcrest-sql    文件:CastMatcher.java   
/**
 * Syntactic sugar for the case where you are merely trying to match a casted value.
 *
 * For example, assertThat(query, hasInQuery(castedValue(literal("11:23:45"))));
 */
@Factory
public static Matcher<QueryTreeNode> castedValue(Matcher<QueryTreeNode> subMatcher) {
    return new CastMatcher(new IsAnything<TypeId>(), subMatcher);
}
项目:hamcrest-sql    文件:TernaryMatcher.java   
/**
 * Syntactic sugar!
 *
 * For example, assertThat(query, hasInQuery(like(column("full_name"), "%Doe%")));
 */
@Factory
public static Matcher<QueryTreeNode> like(Matcher<QueryTreeNode> receiverMatcher, Matcher<QueryTreeNode> leftMatcher) {
    return new TernaryMatcher(receiverMatcher, "LIKE", leftMatcher, new IsAnything<QueryTreeNode>());
}
项目:hamcrest-sql    文件:UnderNodeMatcher.java   
/**
 * Syntactic sugar for the presence of a GROUP BY clause.
 *
 * For example, assertThat(query, groupBy());
 */
@Factory
public static Matcher<QueryTreeNode> groupBy() {
    return new UnderNodeMatcher<QueryTreeNode>(new IsAnything<QueryTreeNode>(), GroupByList.class, "a group by ");
}
项目:hamcrest-sql    文件:UnderNodeMatcher.java   
/**
 * Syntactic sugar for the presence of an ORDER BY clause.
 *
 * For example, assertThat(query, groupBy());
 */
@Factory
public static Matcher<QueryTreeNode> orderBy() {
    return new UnderNodeMatcher<QueryTreeNode>(new IsAnything<QueryTreeNode>(), OrderByList.class, "an order by ");
}
项目:hamcrest-sql    文件:FromSubqueryMatcher.java   
/**
 * Syntactic sugar!
 *
 * For example, assertThat(query, hasInQuery(fromSubquery("my_inner")));
 */
@Factory
public static FromSubqueryMatcher fromSubquery(String tableName) {
    return new FromSubqueryMatcher(new IsAnything<QueryTreeNode>(), tableName);
}