From: James H. <jw...@al...> - 2003-04-21 20:14:37
|
I'm writing a test of a method which needs to make two SQL queries to get the result. I can configure a MockStatement to return two different results, but as far as I can tell, I can't set two expected query values. It seems that if a MockStatement can return multiple result sets, you should be able to associate a specific expected query value with a particular result set. In my case, I have a query which gets a count of something and then uses that count as part of the next query. I would like to test that the count query was correct and also test that the second query was correct. Has anyone run into this problem before, and if so, how did you get around it? Thanks. -- James Howe |
From: Jeff M. <je...@mk...> - 2003-04-22 10:39:49
|
Your probably correct that the MockStatement should be configurable to expect multiple query strings. The best work around would be to actually make a change to the MockStatement so that setExpectedQueryString(String queryString) becomes addExpectedQueryString(String queryString) and myQueryString changes from an ExpectationValue to an ExpectationList. We might want to take things furthur and use the ReturnObjectBag to associate a query with a resultset, but I'm not 100% about this as the Statement interface allows calls to be made to executeUpdate which does not have a ResultSet. Although all the executes do have a return type so it might be okay to have addExpectedQueryStringAndReturn(String query, ResultSet resultSet) addExpectedQueryStringAndReturn(String query, int returnValue) addExpectedQueryStringAndReturn(String query, boolean returnValue) But then again is it better to have. addExpectedExecuteQueryStringAndReturn(String query, ResultSet resultSet) addExpectedExecuteUpdateAndReturn(String query, int returnValue) addExpectedExectuteAndReturn(String query, boolean returnValue) How would you ideally like to use it? On Mon, 2003-04-21 at 21:13, James Howe wrote: > I'm writing a test of a method which needs to make two SQL queries to get > the result. I can configure a MockStatement to return two different > results, but as far as I can tell, I can't set two expected query values. > It seems that if a MockStatement can return multiple result sets, you > should be able to associate a specific expected query value with a > particular result set. In my case, I have a query which gets a count of > something and then uses that count as part of the next query. I would like > to test that the count query was correct and also test that the second > query was correct. Has anyone run into this problem before, and if so, > how did you get around it? > > Thanks. -- Jeff Martin <je...@mk...> |
From: James H. <jw...@al...> - 2003-04-22 14:35:00
|
I guess my preference would be the latter since it more tightly bonds the expectation with the type of call that will be made on the statement. On 22 Apr 2003 11:41:12 +0100, Jeff Martin <je...@mk...> wrote: > Your probably correct that the MockStatement should be configurable to > expect multiple query strings. > > [...] > Although all the executes do have a return type so it might be okay to > have > > addExpectedQueryStringAndReturn(String query, ResultSet resultSet) > addExpectedQueryStringAndReturn(String query, int returnValue) > addExpectedQueryStringAndReturn(String query, boolean returnValue) > > But then again is it better to have. > > addExpectedExecuteQueryStringAndReturn(String query, ResultSet > resultSet) > addExpectedExecuteUpdateAndReturn(String query, int returnValue) > addExpectedExectuteAndReturn(String query, boolean returnValue) > > How would you ideally like to use it? > > > On Mon, 2003-04-21 at 21:13, James Howe wrote: >> I'm writing a test of a method which needs to make two SQL queries to >> get the result. [...] -- James Howe |
From: Jeff M. <je...@mk...> - 2003-04-23 11:55:16
|
Just check in some changes which should help. On Tue, 2003-04-22 at 15:33, James Howe wrote: > I guess my preference would be the latter since it more tightly bonds the > expectation with the type of call that will be made on the statement. > > > On 22 Apr 2003 11:41:12 +0100, Jeff Martin <je...@mk...> wrote: > > > Your probably correct that the MockStatement should be configurable to > > expect multiple query strings. > > > > [...] > > Although all the executes do have a return type so it might be okay to > > have > > > > addExpectedQueryStringAndReturn(String query, ResultSet resultSet) > > addExpectedQueryStringAndReturn(String query, int returnValue) > > addExpectedQueryStringAndReturn(String query, boolean returnValue) > > > > But then again is it better to have. > > > > addExpectedExecuteQueryStringAndReturn(String query, ResultSet > > resultSet) > > addExpectedExecuteUpdateAndReturn(String query, int returnValue) > > addExpectedExectuteAndReturn(String query, boolean returnValue) > > > > How would you ideally like to use it? > > > > > > On Mon, 2003-04-21 at 21:13, James Howe wrote: > >> I'm writing a test of a method which needs to make two SQL queries to > >> get the result. [...] -- Jeff Martin <je...@mk...> |