It was a simple example to show you my point of view. It is not only
about time, but other things also e.g. IO which you mentioned, random
numbers. I am not talking about mocking what you call part of a
language, but util classes which each of us develop as a part of our
systems. What is important it is about util classes which are
unpredictable or interfere with external systems, network etc. I will
never mock my implementation of Math.min() as I don't see any reason
to do it.
Regards,
Bartosz
public class DbUtil {
(...)
public static void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
LOG.debug("Some message");
}
}
}
}
Now, I prefer code like the one below and I don't consider the class
guilty for not begin able to write a test for it:
public class MyClass {
public void doSomething() {
Connection conn = getConnection();
// perform some db operations
DbUtil.close(conn);
}
}
I can inject DbUtil, but is it really a good practice for such a class?
public class MyClass {
private DbUtil dbUtil;
public MyClass(DbUtil dbUtil) {
this.dbUtil = dbUtil;
}
public void doSomething() {
Connection conn = getConnection();
// perform some db operations
dbUtil.close(conn);
}
}
The other solution would be to extract method with close and override
it in the test. But it also doesn't look good to me.
I know that when begin too powerful people can use Mockito not how it
was intended to be used.
Regards,
Bartosz
2008/3/1 szczepiq <szcz...@gmail.com>:
You are right. In the real life application connection is mocked, so
reference to DbUtil is not impacting the test. I guess I should be
more careful when sending code snippets here. The proper example of
the situation I am trying to explain in this thread should not have
any argument in the static method which is called, so that it can't be
mocked.
Regards,
Bartosz
2008/3/3 felix leipold <felix....@googlemail.com>: