org.mockito.internal.matchers.apachecommons.ReflectionEquals Java Examples

The following examples show how to use org.mockito.internal.matchers.apachecommons.ReflectionEquals. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockContextTest.java    From jtwig-core with Apache License 2.0 6 votes vote down vote up
@Test
public void pollFirstMultiple() {
    map.put(IDENTIFIER, blockDefinitionsWithBothNodes);

    assertThat(map.get(IDENTIFIER).size(), is(2));

    Optional<BlockDefinition> definition1 = underTest.pollFirst(IDENTIFIER);
    assertThat(definition1.isPresent(), is(true));
    assertThat(definition1.get(), new ReflectionEquals(blockDefinition1));

    assertThat(map.get(IDENTIFIER).size(), is(1));

    Optional<BlockDefinition> definition2 = underTest.pollFirst(IDENTIFIER);
    assertThat(definition2.isPresent(), is(true));
    assertThat(definition2.get(), new ReflectionEquals(blockDefinition2));

    assertThat(map.get(IDENTIFIER).size(), is(0));
}
 
Example #2
Source File: TokenizerTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 6 votes vote down vote up
@Test
public void assertScanNChars() {
    String sql = "SELECT * FROM ORDER, XX_TABLE AS `table` WHERE YY=N'xx' And group =-1 GROUP BY YY";
    Tokenizer tokenizer = new Tokenizer(sql, dictionary, sql.indexOf("ORDER"));
    assertTrue(new ReflectionEquals(tokenizer.scanIdentifier()).matches(new Token(Literals.IDENTIFIER, "ORDER", sql.indexOf(","))));
    tokenizer = new Tokenizer(sql, dictionary, sql.indexOf("GROUP"));
    assertTrue(new ReflectionEquals(tokenizer.scanIdentifier()).matches(new Token(DefaultKeyword.GROUP, "GROUP", sql.indexOf("BY") - 1)));
    tokenizer = new Tokenizer(sql, dictionary, sql.indexOf("`"));
    assertTrue(new ReflectionEquals(tokenizer.scanIdentifier()).matches(new Token(Literals.IDENTIFIER, "`table`", sql.indexOf("WHERE") - 1)));
    tokenizer = new Tokenizer(sql, dictionary, sql.indexOf("YY"));
    assertTrue(new ReflectionEquals(tokenizer.scanIdentifier()).matches(new Token(Literals.IDENTIFIER, "YY", sql.indexOf("="))));
    tokenizer = new Tokenizer(sql, dictionary, sql.indexOf("=-"));
    assertTrue(new ReflectionEquals(tokenizer.scanSymbol()).matches(new Token(Symbol.EQ, "=", sql.indexOf("=-") + 1)));
    tokenizer = new Tokenizer(sql, dictionary, sql.indexOf("'"));
    assertTrue(new ReflectionEquals(tokenizer.scanChars()).matches(new Token(Literals.CHARS, "xx", sql.indexOf("And") - 1)));
}
 
Example #3
Source File: AbstractBaseParseSQLTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
private void assertOrderBy(final SelectStatement actual) {
    Iterator<OrderItem> orderByColumns = getExpectedOrderByColumns().iterator();
    for (OrderItem each : actual.getOrderByItems()) {
        OrderItem expectedOrderItem = orderByColumns.next();
        assertTrue(new ReflectionEquals(expectedOrderItem).matches(each));
    }
    assertFalse(orderByColumns.hasNext());
}
 
Example #4
Source File: AbstractBaseParseSQLTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
private void assertGroupBy(final SelectStatement actual) {
    Iterator<OrderItem> groupByColumns = getExpectedGroupByColumns().iterator();
    for (OrderItem each : actual.getGroupByItems()) {
        OrderItem groupByColumn = groupByColumns.next();
        assertTrue(new ReflectionEquals(groupByColumn).matches(each));
    }
    assertFalse(groupByColumns.hasNext());
}
 
Example #5
Source File: AbstractBaseParseSQLTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
private void assertAggregationSelectItem(final SelectStatement actual) {
    Iterator<AggregationSelectItem> aggregationSelectItems = getExpectedAggregationSelectItems().iterator();
    for (AggregationSelectItem each : actual.getAggregationSelectItems()) {
        AggregationSelectItem expected = aggregationSelectItems.next();
        assertTrue(new ReflectionEquals(expected, "derivedAggregationSelectItems").matches(each));
        for (int i = 0; i < each.getDerivedAggregationSelectItems().size(); i++) {
            assertTrue(new ReflectionEquals(expected.getDerivedAggregationSelectItems().get(i)).matches(each.getDerivedAggregationSelectItems().get(i)));
        }
    }
    assertFalse(aggregationSelectItems.hasNext());
}
 
Example #6
Source File: AbstractBaseParseSQLTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
private void assertLimit(final SelectStatement actual, final boolean isPreparedStatement) {
    if (null != actual.getLimit()) {
        if (null != actual.getLimit().getOffset()) {
            assertTrue(new ReflectionEquals(buildExpectedLimit(isPreparedStatement).getOffset()).matches(actual.getLimit().getOffset()));
        }
        if (null != actual.getLimit().getRowCount()) {
            assertTrue(new ReflectionEquals(buildExpectedLimit(isPreparedStatement).getRowCount()).matches(actual.getLimit().getRowCount()));
        }
    }
}
 
Example #7
Source File: BlockContextTest.java    From jtwig-core with Apache License 2.0 5 votes vote down vote up
@Test
public void getMultiple() {
    map.put(IDENTIFIER, blockDefinitionsWithBothNodes);

    Optional<BlockDefinition> definition1 = underTest.get(IDENTIFIER, 0);
    assertThat(definition1.isPresent(), is(true));
    assertThat(definition1.get(), new ReflectionEquals(blockDefinition1));

    Optional<BlockDefinition> definition2 = underTest.get(IDENTIFIER, 1);
    assertThat(definition2.isPresent(), is(true));
    assertThat(definition2.get(), new ReflectionEquals(blockDefinition2));
}
 
Example #8
Source File: BlockContextTest.java    From jtwig-core with Apache License 2.0 5 votes vote down vote up
@Test
public void get() {
    map.put(IDENTIFIER, blockDefinitionsWithNode);

    Optional<BlockDefinition> definitionA = underTest.get(IDENTIFIER);
    assertThat(definitionA.isPresent(), is(true));
    assertThat(definitionA.get(), new ReflectionEquals(blockDefinition1));

    Optional<BlockDefinition> definitionB = underTest.get(IDENTIFIER, 0);
    assertThat(definitionB.isPresent(), is(true));
    assertThat(definitionB.get(), new ReflectionEquals(blockDefinition1));
}
 
Example #9
Source File: BlockContextTest.java    From jtwig-core with Apache License 2.0 5 votes vote down vote up
@Test
public void addFirstMultiple() throws Exception {
    underTest.addFirst(blockNode1, resourceReference1);
    underTest.addFirst(blockNode2, resourceReference2);

    assertThat(map.get(IDENTIFIER).get(1), new ReflectionEquals(blockDefinition1));
    assertThat(map.get(IDENTIFIER).get(0), new ReflectionEquals(blockDefinition2));
}
 
Example #10
Source File: BlockContextTest.java    From jtwig-core with Apache License 2.0 5 votes vote down vote up
@Test
public void addLastMultiple() throws Exception {
    underTest.addLast(blockNode1, resourceReference1);
    underTest.addLast(blockNode2, resourceReference2);

    assertThat(map.get(IDENTIFIER).get(0), new ReflectionEquals(blockDefinition1));
    assertThat(map.get(IDENTIFIER).get(1), new ReflectionEquals(blockDefinition2));
}
 
Example #11
Source File: AbstractBaseParseSQLTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
private void assertExpectedConditions(final SQLStatement actual, final boolean isPreparedStatement) {
    assertTrue(new ReflectionEquals(buildExpectedConditions(isPreparedStatement)).matches(actual.getConditions()));
}
 
Example #12
Source File: MockitoHamcrestMatcherAdapter.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public static MockitoHamcrestMatcherAdapter reflectionEquals(final Object wanted, final String... excludeFields) {
    return new MockitoHamcrestMatcherAdapter(new ReflectionEquals(wanted, excludeFields));
}
 
Example #13
Source File: BlockContextTest.java    From jtwig-core with Apache License 2.0 4 votes vote down vote up
@Test
public void addLastFirst() throws Exception {
    underTest.addFirst(blockNode1, resourceReference1);

    assertThat(map.get(IDENTIFIER).peek(), new ReflectionEquals(blockDefinition1));
}
 
Example #14
Source File: BlockContextTest.java    From jtwig-core with Apache License 2.0 4 votes vote down vote up
@Test
public void addLast() throws Exception {
    underTest.addLast(blockNode1, resourceReference1);

    assertThat(map.get(IDENTIFIER).peek(), new ReflectionEquals(blockDefinition1));
}
 
Example #15
Source File: TokenizerTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
private void assertScanHexDecimal(final String sql, final String literals, final TokenType type) {
    String formatSql = String.format(sql, literals);
    Tokenizer tokenizer = new Tokenizer(formatSql, dictionary, sql.indexOf("=") + 1);
    assertTrue(new ReflectionEquals(tokenizer.scanHexDecimal()).matches(new Token(type, literals, formatSql.length())));
}
 
Example #16
Source File: TokenizerTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
private void assertScanNumber(final String sql, final String literals, final TokenType type) {
    String formatSql = String.format(sql, literals);
    Tokenizer tokenizer = new Tokenizer(formatSql, dictionary, sql.indexOf("=") + 1);
    assertTrue(new ReflectionEquals(tokenizer.scanNumber()).matches(new Token(type, literals, formatSql.length())));
}
 
Example #17
Source File: TokenizerTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
private void assertScanVariable(final String sql, final String literals) {
    String formatSql = String.format(sql, literals);
    Tokenizer tokenizer = new Tokenizer(formatSql, dictionary, formatSql.indexOf("@"));
    assertTrue(new ReflectionEquals(tokenizer.scanVariable()).matches(new Token(Literals.VARIABLE, literals, formatSql.indexOf("WHERE") - 1)));
}
 
Example #18
Source File: AbstractBaseParseSQLTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 4 votes vote down vote up
private void assertExpectedTables(final SQLStatement actual) {
    assertTrue(new ReflectionEquals(getExpectedTables()).matches(actual.getTables()));
}
 
Example #19
Source File: Matchers.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Object argument that is reflection-equal to the given value with support for excluding
 * selected fields from a class.
 * <p>
 * This matcher can be used when equals() is not implemented on compared objects.
 * Matcher uses java reflection API to compare fields of wanted and actual object.
 * <p>
 * Works similarly to EqualsBuilder.reflectionEquals(this, other, exlucdeFields) from
 * apache commons library.
 * <p>
 * <b>Warning</b> The equality check is shallow!
 * <p>
 * See examples in javadoc for {@link Matchers} class
 * 
 * @param value
 *            the given value.
 * @param excludeFields
 *            fields to exclude, if field does not exist it is ignored.
 * @return <code>null</code>.
 */
public static <T> T refEq(T value, String... excludeFields) {
    return reportMatcher(new ReflectionEquals(value, excludeFields)).<T>returnNull();
}
 
Example #20
Source File: Matchers.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Object argument that is reflection-equal to the given value with support for excluding
 * selected fields from a class.
 * <p>
 * This matcher can be used when equals() is not implemented on compared objects.
 * Matcher uses java reflection API to compare fields of wanted and actual object.
 * <p>
 * Works similarly to EqualsBuilder.reflectionEquals(this, other, exlucdeFields) from
 * apache commons library.
 * <p>
 * <b>Warning</b> The equality check is shallow!
 * <p>
 * See examples in javadoc for {@link Matchers} class
 * 
 * @param value
 *            the given value.
 * @param excludeFields
 *            fields to exclude, if field does not exist it is ignored.
 * @return <code>null</code>.
 */
public static <T> T refEq(T value, String... excludeFields) {
    return reportMatcher(new ReflectionEquals(value, excludeFields)).<T>returnNull();
}