jmock

jmock mocking a static method

假装没事ソ 提交于 2019-11-27 16:03:20
I have a static method in my code that I would like somehow to mock. I am using jmock. One way I suppose I could do this is to have "wrapper class" around the static method and mock this but I was hoping for a better solution. I am going about this the wrong way? FEEDBACK: I was going to have a interface and class that had a method that just called the static method. It would allow me to mock the logic by just mocking the call to this wrapper class. (I feel dirty even talking about it :) ) We don't support mocking static methods in jMock because it doesn't fit our design approach. We prefer

Is there a simple way to match a field using Hamcrest?

孤街浪徒 提交于 2019-11-27 03:40:47
问题 I want to test whether a specific field of an object matches a value I specify. In this case, it's the bucket name inside an S3Bucket object. As far as I can tell, I need to write a custom matcher for this: mockery.checking(new Expectations() {{ one(query.s3).getObject(with( new BaseMatcher<S3Bucket>() { @Override public boolean matches(Object item) { if (item instanceof S3Bucket) { return ((S3Bucket)item).getName().equals("bucket"); } else { return false; } } @Override public void describeTo

jmock mocking a static method

醉酒当歌 提交于 2019-11-26 18:34:33
问题 I have a static method in my code that I would like somehow to mock. I am using jmock. One way I suppose I could do this is to have "wrapper class" around the static method and mock this but I was hoping for a better solution. I am going about this the wrong way? FEEDBACK: I was going to have a interface and class that had a method that just called the static method. It would allow me to mock the logic by just mocking the call to this wrapper class. (I feel dirty even talking about it :) )