Fork me on GitHub

Usage

ConditionBean Matchers

This library provides Matchers for query conditions (cb.query().setXXX) and for fetching column (cb.specify().columnXXX).

You can use these matchers by import statically org.dbflute.testing.DBFluteMatchers. Please refer to JavaDoc API for complete list of APIs.

Assert query conditions

These matchers are intended to use with assertThat method.

To test condition for column, use hasCondition with a operator matcher.

assertThat(cb, hasCondition("memberName", equal("John Doe")));

The first argument (“memberName”) is a String of column name. This is a case-insensitive and accepting both camel case and snake case.

You can pass any Matcher instance to the operator matcher (equal(...) in above).

assertThat(cb, hasCondition("memberName", equal(startsWith("John"))));

Assert query conditions on joined table

cb.query().queryMemberStatus().setMemberStatusName_NotEqual("DEL");
cb.query().queryMemberServiceAsOne().queryServiceRank().setRankName_Equal("VIP");

assertThat(cb, hasRelation("memberStatus", hasCondition("memberName", notEqual("DEL"))));
assertThat(cb, hasRelation("memberService.serviceRank", hasCondition("rankName", equal("ACT"))));

Assert column should select

cb.specify().columnMemberName();
assertThat(cb, shouldSelect("memberName"));

Assert that should select columns of joind table

cb.specify().specifyMemberStatus().columnMemberStatusName();
cb.specify().specifyMemberServiceAsOne().specifyServiceRank().columnServiceRankName();

assertThat(cb, shouldSelect("memberStatus.memberStatusName"));
assertThat(cb, shouldSelect("memberService.serviceRank.serviceRankName"));

Mockito helpers

Argument Captor

bhv.selectEntity(cb -> cb.query().setMemberId_Equal(1));

BehaviorArgumentCaptor<MemberCB> captor = captor(MemberCB.class);
verify(bhv).selectEntity(captor.capture());

MemberCB cb = captor.getCB();
assertThat(cb, hasCondition("memberId", equal(1)));

Argument Matcher

when(bhv.selectEntity(argCB(MemberCB.class, hasCondition("memberId", equal(1))))).thenReturn(fixture);

verify(mockBhv).selectEntity(argCB(MemberCB.class, hasCondition("memberId", equal(1))));

JUnit helpers

AccessContextInitializer

public class FooTest {
    @Rule
    public AccessContextInitializer ac = new AccessContextInitializer("foo");

    @AutoWired
    MemberBhv bhv;

    @Test
    public void insert() {
        Member m = new Member();
        m.setMemberName("John Doe");
        bhv.insert(m);
        assertThat(m.getRegisterUser(), is("foo"));
    }
}

JUnit Category

@DatabaseTests is a JUnit @Category annotation. Please refer to JUnit wiki for details of categories.

https://github.com/junit-team/junit/wiki/Categories

<plugin>
	<artifactId>maven-surefire-plugin</artifactId>
	<configuration>
		<excludedGroups>org.dbflute.testing.category.DatabaseTests</excludedGroups>
	</configuration>
</plugin>