<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:syn="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/">
  <channel rdf:about="http://blog.gmane.org/gmane.comp.java.jmock.user">
    <title>gmane.comp.java.jmock.user</title>
    <link>http://blog.gmane.org/gmane.comp.java.jmock.user</link>
    <description/>
    <syn:updatePeriod>hourly</syn:updatePeriod>
    <syn:updateFrequency>1</syn:updateFrequency>
    <syn:updateBase>1901-01-01T00:00+00:00</syn:updateBase>
    <items>
      <rdf:Seq>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2027"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2026"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2025"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2024"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2023"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2022"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2021"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2020"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2019"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2018"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2017"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2016"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2015"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2014"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2013"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2012"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2011"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2010"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2009"/>
        <rdf:li rdf:resource="http://permalink.gmane.org/gmane.comp.java.jmock.user/2008"/>
      </rdf:Seq>
    </items>
    <image rdf:resource="http://gmane.org/img/gmane-25t.png"/>
    <textinput rdf:resource=""/>
  </channel>
  <image rdf:about="http://gmane.org/img/gmane-25t.png">
    <title>Gmane</title>
    <url>http://gmane.org/img/gmane-25t.png</url>
    <link>http://gmane.org</link>
  </image>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2027">
    <title>Re: how to test property of argument passed to method?</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2027</link>
    <description>

This is very close to what I was originally trying to do, and quite
readable.

L
</description>
    <dc:creator>Limbic System</dc:creator>
    <dc:date>2008-10-05T03:27:43</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2026">
    <title>Re: how to test property of argument passed to method?</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2026</link>
    <description>It sure seems like something could be done in the API to make it simpler,
but I'm not sure what. So let me think out loud here.

What we really want is the ability to explicitly specify the type parameter
like in C++ where you could say

 with&lt; Bob &gt;( hasProperty(...) )

Java does have explicit type parameters for methods, but it only works if
qualified with this for an instance method or the class name for static
methods (See &lt;
http://www.angelikalanger.com/GenericsFAQ/FAQSections/TechnicalDetails.html#What%20explicit%20type%20argument%20specification?&gt;).
You would have to do something like this:

 this.&lt; Bob &gt;with( hasProperty(...) )

It seems you could accomplish the same thing just using casting since with
is going to return null any way:

   one(mock).myMethod( (Bob)with(hasProperty("prop", equalTo("value") ) );

I have said it before, but I think the generic parameter on Matcher was a
bad idea and adds no value. At the very least there should have been
non-generic matchers and generic ones are subinterface of that. hasProperty
should return the non-generic Matcher while some other method could return a
generic one. Then you can overload differently based on generic or
non-generic.

Perhaps it might be good to have a with method that takes a class parameter
(Note I used ... to allow multiple Matchers that are anded together):

   T with( Class&lt;T&gt; clazz, Matcher&lt; ? &gt;... matcher )

This is essentially the same as:

     (T)with( allOf( is( clazz ), allOf( matcher ) ) ) );

Which could then be used as

one(mock).myMethod( with(Bob.class, hasProperty("prop", equalTo("value") )
);


On Thu, Oct 2, 2008 at 3:54 PM, Limbic System &lt;limbicsystem-Re5JQEeQqe8AvxtiuMwx3w&lt; at &gt;public.gmane.org&gt;wrote:



</description>
    <dc:creator>Dale King</dc:creator>
    <dc:date>2008-10-02T21:38:08</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2025">
    <title>Re: how to test property of argument passed to method?</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2025</link>
    <description>Nat,
Thanks for your speedy reply.  Too bad the generics don't allow that syntax,
but at least now I can stop banging my head against the desk. :-)

L

On Thu, Oct 2, 2008 at 1:37 AM, Nat Pryce &lt;nat.pryce-Re5JQEeQqe8AvxtiuMwx3w&lt; at &gt;public.gmane.org&gt; wrote:

</description>
    <dc:creator>Limbic System</dc:creator>
    <dc:date>2008-10-02T19:54:43</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2024">
    <title>Re: how to test property of argument passed to method?</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2024</link>
    <description>Unfortunately, Java's generics are crap, so while the following doesn't compile:

    one(mock).myMethod(with(hasProperty("prop", eq("value"))));

The following does:

    Matcher&lt;Bob&gt; propEqualToValue = hasProperty("prop", equalTo("value");
    one(mock).myMethod(with(propEqualToValue));

Maybe they'll make generics work one day, but until then we'll have to
use awkward workarounds like that.

--Nat

2008/10/2 Limbic System &lt;limbicsystem-Re5JQEeQqe8AvxtiuMwx3w&lt; at &gt;public.gmane.org&gt;:

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Nat Pryce</dc:creator>
    <dc:date>2008-10-02T05:37:56</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2023">
    <title>how to test property of argument passed to method?</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2023</link>
    <description>What is the proper way to test a property of an argument passed into a
method of a mock, under JMock 2.5?

Let's say that my CUT would normally be called like:

   myObject.myMethod(arg);

and I'd like to verify that "arg" is of a particular type, and that it has a
particular property set.  I'm trying to do this:

   one(mock).myMethod(with(hasProperty("prop", eq("value"))));

but hasProperty() returns Object, while myMethod() is expecting type
Argument.

I *can* do the following, which works:

   one(mock).myMethod(with(any(Argument.class)));

I've been googling this problem for 2 days now, so any help would be greatly
appreciated, thanks.
</description>
    <dc:creator>Limbic System</dc:creator>
    <dc:date>2008-10-02T03:19:19</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2022">
    <title>Re: "java.lang.IllegalArgumentException: a mock with name ... already exists" with jmock2.5.0</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2022</link>
    <description>It looks like the context is hanging on to both collectors, which  
would mean that they need a name. What's happening around these tests?  
How do you manage your context object?

S.

On 19 Sep 2008, at 02:42, 王軍＠Neusoft wrote:


Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England &amp; Wales. Number 03689627



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Steve Freeman</dc:creator>
    <dc:date>2008-09-19T06:23:05</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2021">
    <title>Re: "java.lang.IllegalArgumentException: a mock with name ... already exists" with jmock2.5.0</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2021</link>
    <description>Give your mock Collectors explicit names that are different and
explain what is different between them.

--Nat

2008/9/19 王軍＠Neusoft &lt;wangjun-YYSg24PYQUdBDgjK7y7TUQ&lt; at &gt;public.gmane.org&gt;:

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Nat Pryce</dc:creator>
    <dc:date>2008-09-19T06:19:58</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2020">
    <title>"java.lang.IllegalArgumentException: a mock with name ... already exists" with jmock2.5.0</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2020</link>
    <description>Hi

I got a problem with jmock2.5.0.

Below is my tests that past under jmock2.2.0. After upgrading jmock to 
2.5.0, these tests got failed with the stack trace below.

    &lt; at &gt;Test
    public void testCollectMissDataRight() throws Exception {
        final Collector  collector0 = context.mock(Collector.class);
        final SocketSession fSession = context.mock(SocketSession.class);

        MaintenanceSession session =
            new MaintenanceSession(null,collector0);

        context.checking(new Expectations() {
            {
                one(collector0).isConnectedSector(with(equal("TACC00")));
                will(returnValue(fSession));
                one(fSession).startCollectLeftData((byte[])with(anything()));

            }
        });
        byte[] data = "0000004820000001234567890123456789012345678999 
TACC00  ".getBytes();
        session.processData(data);
        context.assertIsSatisfied();
    }

    &lt; at &gt;Test
    public void testCollectMissDataWrong() throws Exception {
        final Collector  collector1 = context.mock(Collector.class);
        final SocketSession fSession1 = context.mock(SocketSession.class);

        MaintenanceSession session =
            new MaintenanceSession(null,collector1);

        context.checking(new Expectations() {
            {
                one(collector1).isConnectedSector(with(equal("TACC00")));
                will(returnValue(null));
                never(fSession1).startCollectLeftData((byte[])with(anything()));
                one(collector1).processAPError((String)with(anything()));
            }
        });
        byte[] data = "0000004820000001234567890123456789012345678999 
TACC00  ".getBytes();
        session.processData(data);
        context.assertIsSatisfied();
    }


java.lang.IllegalArgumentException: a mock with name collector already 
exists
 at org.jmock.Mockery.mock(Mockery.java:128)
 at org.jmock.Mockery.mock(Mockery.java:120)
 at 
rae07a.collect.MaintenanceSessionTest.testCollectMissDataWrong(MaintenanceSessionTest.java:45)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:585)
 at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
 at 
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
 at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
 at 
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
 at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
 at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
 at 
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
 at 
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
 at 
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
 at 
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
 at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
 at 
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
 at 
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
 at 
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
 at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
 at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
 at 
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

I got into jmock2.50 source and found out this problem has something to do 
with defaultNameFor method which always gives the same name for the same 
class.

    public &lt;T&gt; T mock(Class&lt;T&gt; typeToMock) {
  return mock(typeToMock, namingScheme.defaultNameFor(typeToMock));
 }

Maybe this is supposed to do. Can anybody help me with some answer?

James



----------------------------------------------------------------------------------------------
Confidentiality Notice: The information contained in this e-mail and any
accompanying attachment(s) is intended only for the use of the intended
recipient and may be confidential and/or privileged of Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful. If you have received this communication in error, please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you. 
-----------------------------------------------------------------------------------------------

</description>
    <dc:creator>王軍＠Neusoft</dc:creator>
    <dc:date>2008-09-19T01:42:24</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2019">
    <title>Re: how to test exception condition in Junit</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2019</link>
    <description>This message

org.jmock.core.DynamicMockError: mockHttpServletRequest: unexpected  
invocation
Invoked: mockHttpServletRequest.getParameter("beginDate")
Allowed:
expected once and has been invoked: getParameter( eq("distId") ),  
returns null

is telling you that you called getParameter() but didn't set up either  
a stub or expectation, so the mock doesn't know what to do.


S.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Steve Freeman</dc:creator>
    <dc:date>2008-09-17T07:10:44</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2018">
    <title>how to test exception condition in Junit</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2018</link>
    <description>i am trying to write a test case for the exception scenario.
my code looks as below.


*public* ActionForward execute(ActionMapping mapping, ActionForm actionForm,
HttpServletRequest request, HttpServletResponse response) *throws* Exception
{

ActionForward actionforward = *null*;

*try*{

SimpleDateFormat format = *new* SimpleDateFormat(ReportingConstant.*
DATE_FORMAT*);

ReportRequest reportReq = *new* ReportRequest();

String distID = request.getParameter("distId");

String beginDate = request.getParameter("beginDate");

String endDate = request.getParameter("endDate");

*if*(*null* != beginDate){

reportReq.setBeginDate(format.parse(beginDate));

}*else*{

*LOG*.error("Begin date not present in the received form ");

*throw* *new* ReportingException("Begin date not present in the received
form");

}

*if*(*null* != endDate){

reportReq.setEndDate(format.parse(endDate));

}*else*{

*LOG*.error("End date not present in the received form ");

*throw* *new* ReportingException("End date not present in the received form"
);

}

*if*(*null* != distID){

reportReq.setDistributorId(distID);

}*else*{

*LOG*.error("Distributor Id not present in the received form ");

*throw* *new* ReportingException("Distributor Id not present in the received
form ");

}

some code....

}*catch*(Exception e){

*LOG*.error("Error sending XLS file to the client ",e);

actionforward = mapping.findForward("exception");

}

*return* actionforward;

}



now i would like to test a execute method for exception i.e. i am expecting
that if the request obj do not have any parameters set then my code will
throw an exception.

and i need to verify that.

my test case method is like..

*public* *void* testDownloadXLSReportFailure()*throws* Exception{

httpServletRequestMock.expects(once())

.method("getParameter")

.with(eq("distId"))

.will(returnValue(*null*));

request = (HttpServletRequest)httpServletRequestMock.proxy();

*try*{

ActionForward forward = downloadReportAction.execute(actionMapping,
reportForm, request, response);

*fail*("Error ..");

}*catch*(Exception e){

}

}

org.jmock.core.DynamicMockError: mockHttpServletRequest: unexpected
invocation
Invoked: mockHttpServletRequest.getParameter("beginDate")
Allowed:
expected once and has been invoked: getParameter( eq("distId") ), returns
null

 at
org.jmock.core.AbstractDynamicMock.mockInvocation(AbstractDynamicMock.java:58)
 at org.jmock.cglib.CGLIBCoreMock.intercept(CGLIBCoreMock.java:71)
 at
$javax.servlet.http.HttpServletRequest$$EnhancerByCGLIB$$7c120c24.getParameter(&lt;generated&gt;)
 at
com.toro.rebate.reporting.struts.action.DownloadXLSCommercialReportAction.execute(DownloadXLSCommercialReportAction.java:47)
 at
com.toro.rebate.reporting.struts.action.DownloadXLSCommercialReportActionTest.testDownloadXLSReportFailure(DownloadXLSCommercialReportActionTest.java:116)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)
 at junit.framework.TestCase.runTest(TestCase.java:154)
 at org.jmock.core.VerifyingTestCase.runBare(VerifyingTestCase.java:39)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:118)
 at junit.framework.TestSuite.runTest(TestSuite.java:208)
 at junit.framework.TestSuite.run(TestSuite.java:203)
 at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
 at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

can sombody tell me how do i chk the exception condition here?



thanks,

sush
</description>
    <dc:creator>Sushil Dodake</dc:creator>
    <dc:date>2008-09-16T21:44:53</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2017">
    <title>Re: writing test case for struts action?</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2017</link>
    <description>1. Buy some of the TDD books. There are quite a few good ones out there.

2. In your case, create a concrete subclass of the ServletOutputStream  
that writes to a StringBuffer and compare the result at the end of the  
test. Once you're used to that, we can consider what to do next.

S.

On 16 Sep 2008, at 05:21, Sushil Dodake wrote:

Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England &amp; Wales. Number 03689627



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Steve Freeman</dc:creator>
    <dc:date>2008-09-16T08:39:09</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2016">
    <title>Re: writing test case for struts action?</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2016</link>
    <description>Have you considered mocking the HttpServletResponse and asserting that an output
stream is retrieved from it?

On Tue 16/09/08 06:21 , "Sushil Dodake" sushil.dodake-Re5JQEeQqe8AvxtiuMwx3w&lt; at &gt;public.gmane.org sent:



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Stephen Smith</dc:creator>
    <dc:date>2008-09-16T08:09:36</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2015">
    <title>writing test case for struts action?</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2015</link>
    <description>Hi All,
i am trying to write a test case for a struts action call.
in the action call i am trying to send a file on the response output stream.
when i get the output stream using response.getOutputstream i get a object
of ServletOurtputStream.
which is a abstract class..
 i then write a byte stream on the output stream and fluch it to close
i am confused as to how to write a test case.
can sombody help me here?
any example?

regards,

Sush
</description>
    <dc:creator>Sushil Dodake</dc:creator>
    <dc:date>2008-09-16T04:21:22</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2014">
    <title>Re: Can I mock an enum</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2014</link>
    <description>Enums can implement interfaces, so you can define an interface that
defines how an object using an enum type interacts with instances of
that enum, and then mock the interface.

As someone else pointed out, enum classes are final and so you can't
mock them.  However, the jDave project has an "unfinalizer" that you
can use to remove final-ness from classes as they are loaded into the
JVM.  With that, you can use the ClassImposteriser to mock final
classes.  However, reaching for that kind of magic is a clear smell
that something is not quite right with your design.

--Nat

2008/9/12 Avinash Nayak &lt;avi_gaming-/E1597aS9LQAvxtiuMwx3w&lt; at &gt;public.gmane.org&gt;:

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Nat Pryce</dc:creator>
    <dc:date>2008-09-14T10:30:49</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2013">
    <title>Re: Can I mock an enum</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2013</link>
    <description>First of all, the code snippet was just to convey my message.
The method i want to test depends on Strategy.getValue().
Though its a simple Boolean here. it may not be the case also.
So while testing myMethod() I could ensure it uses only getValue method
 out of Strategy class.
And I could have mocked the returnValue and go ahead with the test.

Otherwise, I would have to test the given method by 
 passing all the enum values out of Strategy Enum.
Passing for a single enum value, doesnt say the test has succeeded.
And there might be case that i have 10-12 values in the enum.

Anyway, it was nice to see some good comments... :)

Thanks again.



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Avinash</dc:creator>
    <dc:date>2008-09-13T08:19:21</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2012">
    <title>Re: Re: Can I mock an enum</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2012</link>
    <description>You should be using mocks to test interactions with neighbouring  
objects that represent "interesting" behaviour. For simple value  
objects which includes simple value objects, I'd just use a real one.  
Either the Strategy makes a difference to the behaviour of the unit  
tested code, in which case you want to test the effect, or it doesn't,  
in which case any of the values will work.

See also

http://www.mockobjects.com/2007/04/test-smell-everything-is-mocked.html

S.


On 13 Sep 2008, at 07:41, Avinash wrote:

Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England &amp; Wales. Number 03689627



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Steve Freeman</dc:creator>
    <dc:date>2008-09-13T07:52:03</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2011">
    <title>Re: Can I mock an enum</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2011</link>
    <description>I got what you guys saying.
Understood the fact that the enums are final
 and hence cant mock them using jmock rather with ClasssImposteriser.INSTANCE.
Still will try to convince what i was trying to achieve.
I am posting a code snippet. this is quite simple version of my code.

public enum Strategy {
StrategyTrue(Boolean.TRUE), StrategyFalse(Boolean.FALSE), StrategyNone(null);

private Boolean value;

private Strategy(Boolean value) {
this.value = value;
}

public Boolean getValue() {
return value;
}
}

public class MyClass {
public Boolean myMethod(Strategy strategy) {
return strategy.getValue();
}
}

public class MyClassUTEST extends TestCase {
public void test_myMethod() {
// Mocked Value;
final Boolean mockedValue = Boolean.TRUE;

Mockery context = new Mockery();
context.setImposteriser(ClassImposteriser.INSTANCE);
final Strategy strategy = context.mock(Strategy.class);

context.checking(new Expectations() {
{
oneOf(strategy).getValue();
will(returnValue(mockedValue));
}
});

assertEquals(mockedValue, new MyClass().myMethod(strategy));
context.assertIsSatisfied();
}
}

This way a single testcase can cover all the test scenarios of the method.
Otherwise, i would have to write test for each Enum value.
I could make it work by changing the enum in the following way.

public enum Strategy {
StrategyTrue() {
&lt; at &gt;Override
public Boolean getValue() {
return Boolean.TRUE;
}
},
StrategyFalse() {
&lt; at &gt;Override
public Boolean getValue() {
return Boolean.FALSE;
}
},
StrategyNone() {
&lt; at &gt;Override
public Boolean getValue() {
return null;
}
};

public abstract Boolean getValue();
}

But still, i would have appreciated the first attempt.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Avinash</dc:creator>
    <dc:date>2008-09-13T06:41:07</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2010">
    <title>Re: Can I mock an enum</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2010</link>
    <description>On Fri, Sep 12, 2008 at 3:08 PM, Stephen Smith
&lt;steve-cOXOJo/IntmS2QFrQHbrDfXRex20P6io&lt; at &gt;public.gmane.org&gt; wrote:

Really?  What do you usually mock?

Pat

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Pat Maddox</dc:creator>
    <dc:date>2008-09-12T22:01:20</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2009">
    <title>Re: Testing a subclass</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2009</link>
    <description>I'd say test the whole thing together. If there's behaviour in the  
parent that is complex enough to need special handling, then extract  
another object and use composition.

Sorry for being so ornery.

S.

On 12 Sep 2008, at 14:18, Chris O'Connell wrote:




Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England &amp; Wales. Number 03689627



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Steve Freeman</dc:creator>
    <dc:date>2008-09-12T20:01:31</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2008">
    <title>Re: Can I mock an enum</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2008</link>
    <description>The Jakarta Commons Lang Enum package is far better than the Java5
implementation, but mocking domain objects or enumerated types seems like a code 
smell to me.

Exactly what behaviour are you trying to assert?

Steve.

---
Stephen Smith, MEng (Wales).
http://www.stephen-smith.co.uk/

Avinash Nayak wrote:

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Stephen Smith</dc:creator>
    <dc:date>2008-09-12T19:08:30</dc:date>
  </item>
  <item rdf:about="http://permalink.gmane.org/gmane.comp.java.jmock.user/2007">
    <title>Re: Can I mock an enum</title>
    <link>http://permalink.gmane.org/gmane.comp.java.jmock.user/2007</link>
    <description>Firstly, I don't believe you can.

Secondly, I would just use one of the enums directly in the test case,  
as an example. If an enum is that complicated, it should defer to  
other objects.

S.

On 12 Sep 2008, at 12:01, Avinash Nayak wrote:



Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England &amp; Wales. Number 03689627



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



</description>
    <dc:creator>Steve Freeman</dc:creator>
    <dc:date>2008-09-12T18:01:25</dc:date>
  </item>
  <textinput rdf:about="http://search.gmane.org/?group=$group=gmane.comp.java.jmock.user">
    <title>Search Engine</title>
    <description>Search the mailing list at Gmane</description>
    <name>query</name>
    <link>http://search.gmane.org/?group=$group=gmane.comp.java.jmock.user</link>
  </textinput>
</rdf:RDF>
