Skip to content

Instantly share code, notes, and snippets.

@sizovs
Last active December 1, 2020 21:04
Show Gist options
  • Save sizovs/4974a2b04659371b25612d578d1e3d70 to your computer and use it in GitHub Desktop.
Save sizovs/4974a2b04659371b25612d578d1e3d70 to your computer and use it in GitHub Desktop.
import org.hibernate.Session
import org.hibernate.SessionFactory
import org.hibernate.query.NativeQuery
import org.hibernate.query.Query
class SomeRepoSpec extends Specification {
def sessionFactory = Mock(SessionFactory)
def repo = new FundingRepository(sessionFactory);
def 'should list something'() {
given:
def sqlQuery = Mock()
def nativeQuery = Mock()
def session = Mock()
when:
repo.findSomething(...)
then:
1 * sessionFactory.getCurrentSession() >> session
1 * session.createSQLQuery({ it.contains('find_something') } as String) >> nativeQuery
1 * nativeQuery.setString("criteria", "{\"a\":223,\"criteria\":{\"b\":35},\"c\":\"2019-01-01 00:00:11\"}") >> sqlQuery
and:
then:
1 * sessionFactory.getCurrentSession() >> session
1 * session.createSQLQuery({ it.contains('get_new_amount_snapshot') } as String) >> nativeQuery
1 * nativeQuery.setLong('loanId', bean.loanId) >> sqlQuery
1 * sqlQuery.setLong('x', 1) >> sqlQuery
1 * sqlQuery.setString('y', 2) >> sqlQuery
1 * sqlQuery.setString("z", _ as String) >> sqlQuery
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment