View Javadoc

1   /***
2    * Created on Mar 22, 2004 by jdt
3    * Auto generated using mockmaker
4   * Copyright (C) AstroGrid. All rights reserved.
5   *
6   * This software is published under the terms of the AstroGrid 
7   * Software License version 1.2, a copy of which has been included 
8   * with this distribution in the LICENSE.txt file.
9   * */
10  package org.astrogrid.portal.cocoon.messaging;
11  import javax.mail.Session;
12  import mockmaker.ReturnValues;
13  import mockmaker.VoidReturnValues;
14  import mockmaker.ExceptionalReturnValue;
15  import com.mockobjects.*;
16  import org.astrogrid.portal.cocoon.messaging.Messenger;
17  import org.astrogrid.portal.cocoon.messaging.MessengerException;
18  public class MockEmailMessenger implements Messenger {
19      private ExpectationCounter mySendMessageCalls =
20          new ExpectationCounter("org.astrogrid.portal.cocoon.messaging.EmailMessenger SendMessageCalls");
21      private ReturnValues myActualSendMessageReturnValues =
22          new VoidReturnValues(false);
23      private ExpectationList mySendMessageParameter0Values =
24          new ExpectationList("org.astrogrid.portal.cocoon.messaging.EmailMessenger java.lang.String");
25      private ExpectationList mySendMessageParameter1Values =
26          new ExpectationList("org.astrogrid.portal.cocoon.messaging.EmailMessenger java.lang.String");
27      public void setExpectedSendMessageCalls(int calls) {
28          mySendMessageCalls.setExpected(calls);
29      }
30      public void addExpectedSendMessageValues(String arg0, String arg1) {
31          mySendMessageParameter0Values.addExpected(arg0);
32          mySendMessageParameter1Values.addExpected(arg1);
33      }
34      public void sendMessage(String arg0, String arg1)
35          throws MessengerException {
36          mySendMessageCalls.inc();
37          mySendMessageParameter0Values.addActual(arg0);
38          mySendMessageParameter1Values.addActual(arg1);
39          Object nextReturnValue = myActualSendMessageReturnValues.getNext();
40          if (nextReturnValue instanceof ExceptionalReturnValue
41              && ((ExceptionalReturnValue) nextReturnValue).getException()
42                  instanceof MessengerException)
43              throw (MessengerException)
44                  ((ExceptionalReturnValue) nextReturnValue)
45                  .getException();
46          if (nextReturnValue instanceof ExceptionalReturnValue
47              && ((ExceptionalReturnValue) nextReturnValue).getException()
48                  instanceof RuntimeException)
49              throw (RuntimeException) ((ExceptionalReturnValue) nextReturnValue)
50                  .getException();
51      }
52      public void setupExceptionSendMessage(Throwable arg) {
53          myActualSendMessageReturnValues.add(new ExceptionalReturnValue(arg));
54      }
55      public void verify() {
56          mySendMessageCalls.verify();
57          mySendMessageParameter0Values.verify();
58          mySendMessageParameter1Values.verify();
59      }
60      private String recipient;
61      private Session session;
62      public MockEmailMessenger(final Session session, final String recipient) {
63          this.recipient = recipient;
64          this.session = session;
65      }
66      /***
67       * getter
68       * @return Returns the recipient.
69       */
70      public String getRecipient() {
71          return recipient;
72      }
73  
74      /***
75       * getter
76       * @return Returns the session.
77       */
78      public Session getSession() {
79          return session;
80      }
81  
82  }