git clone of logicmail with some fixes/features added
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix for escaped dot issue with POP and SMTP (refs #348) and initial unit tests for POP and SMTP.

git-svn-id: https://logicmail.svn.sourceforge.net/svnroot/logicmail/trunk@919 5c734088-3d25-0410-9155-b3c3832efda5

octorian 7c676aeb d3d66041

+1069 -84
+8 -1
LogicMail/src/org/logicprobe/LogicMail/mail/NetworkSendMessageRequest.java
··· 78 78 OutgoingMailClient outgoingClient = (OutgoingMailClient)client; 79 79 80 80 showStatus(outgoingClient, resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_SEND_MESSAGE)); 81 - String messageSource = outgoingClient.sendMessage(envelope, message); 81 + byte[] rawMessage = outgoingClient.sendMessage(envelope, message); 82 + String messageSource; 83 + if(rawMessage != null && rawMessage.length > 0) { 84 + messageSource = new String(rawMessage); 85 + } 86 + else { 87 + messageSource = null; 88 + } 82 89 83 90 mailSender.fireMessageSent(envelope, message, messageSource); 84 91 }
+1 -1
LogicMail/src/org/logicprobe/LogicMail/mail/OutgoingMailClient.java
··· 48 48 * @throws IOException on I/O errors 49 49 * @throws MailException on protocol errors 50 50 */ 51 - public abstract String sendMessage(MessageEnvelope envelope, Message message) throws IOException, MailException; 51 + public abstract byte[] sendMessage(MessageEnvelope envelope, Message message) throws IOException, MailException; 52 52 }
+29 -48
LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopProtocol.java
··· 93 93 ("PopProtocol.executeCapa()").getBytes(), 94 94 EventLogger.DEBUG_INFO); 95 95 } 96 - String[] replyText = executeFollow(CAPA, false, null); 96 + byte[][] replyText = executeFollowBinary(CAPA, false, null); 97 97 98 98 if ((replyText == null) || (replyText.length < 1)) { 99 99 return null; ··· 102 102 Hashtable table = new Hashtable(); 103 103 104 104 for(int i=0; i<replyText.length; i++) { 105 - int p = replyText[i].indexOf(' '); 106 - int len = replyText[i].length(); 105 + String replyLine = new String(replyText[i]); 106 + int p = replyLine.indexOf(' '); 107 + int len = replyLine.length(); 107 108 if(p != -1 && p + 1 < len) { 108 - table.put(replyText[i].substring(0, p), replyText[i].substring(p + 1, len)); 109 + table.put(replyLine.substring(0, p), replyLine.substring(p + 1, len)); 109 110 } 110 111 else { 111 - table.put(replyText[i], Boolean.TRUE); 112 + table.put(replyLine, Boolean.TRUE); 112 113 } 113 114 } 114 115 ··· 373 374 * if <code>errorFatal</code> is <code>false</code> and the 374 375 * response was an error. 375 376 */ 376 - private String[] executeFollow(String command, boolean errorFatal, MailProgressHandler progressHandler) throws IOException, MailException { 377 - int preCount = connection.getBytesReceived(); 378 - watchdog.start(); 379 - if(executeImpl(command, errorFatal) == null) { 380 - watchdog.cancel(); 381 - return null; 382 - } 383 - 384 - String buffer = new String(connection.receive()); 385 - watchdog.kick(); 386 - 387 - int postCount = connection.getBytesReceived(); 388 - if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 389 - 390 - String[] lines = new String[0]; 391 - while(buffer != null && !buffer.equals(".")) { 392 - Arrays.add(lines, buffer); 393 - preCount = postCount; 394 - buffer = new String(connection.receive()); 395 - watchdog.kick(); 396 - 397 - postCount = connection.getBytesReceived(); 398 - if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 399 - } 400 - watchdog.cancel(); 401 - return lines; 402 - } 403 - 404 - /** 405 - * Execute a POP3 command that returns multiple lines. 406 - * This works by running the normal execute() and then receiving every new 407 - * line until a lone "." is encountered. 408 - * 409 - * @param command The command to execute 410 - * @param errorFatal If true, then an "-ERR" response to the command will 411 - * generate an exception. 412 - * @param progressHandler progress handler 413 - * @return An array of lines containing the response, or <code>null</code> 414 - * if <code>errorFatal</code> is <code>false</code> and the 415 - * response was an error. 416 - */ 417 377 private byte[][] executeFollowBinary(String command, boolean errorFatal, MailProgressHandler progressHandler) throws IOException, MailException { 418 378 int preCount = connection.getBytesReceived(); 419 379 watchdog.start(); ··· 429 389 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 430 390 431 391 byte[][] lines = new byte[0][]; 432 - while(buffer != null && !(buffer.length == 1 && buffer[0] == (byte)'.')) { 433 - Arrays.add(lines, buffer); 392 + while(buffer != null && !(buffer.length == 1 && buffer[0] == CHAR_PERIOD)) { 393 + Arrays.add(lines, unescapeDots(buffer)); 434 394 preCount = postCount; 435 395 buffer = connection.receive(); 436 396 watchdog.kick(); ··· 440 400 } 441 401 watchdog.cancel(); 442 402 return lines; 403 + } 404 + 405 + /** 406 + * Removes escaped dots from POP responses. 407 + * 408 + * According to RFC 1939, lines starting with '.' in multi-line POP 409 + * responses are escaped by adding an additional dot in the beginning, 410 + * which should be discarded when processing the response. 411 + * 412 + * @param lineData the line of the server response to process 413 + * @return version of the line with leading dots un-escaped 414 + */ 415 + private static byte[] unescapeDots(byte[] lineData) { 416 + if(lineData != null && lineData.length > 1 417 + && lineData[0] == CHAR_PERIOD && lineData[1] == CHAR_PERIOD) { 418 + return Arrays.copy(lineData, 1, lineData.length - 1); 419 + } 420 + else { 421 + return lineData; 422 + } 443 423 } 444 424 445 425 /** ··· 523 503 "password", 524 504 "invalid" 525 505 }; 506 + private static final byte CHAR_PERIOD = (byte)'.'; 526 507 }
+28 -19
LogicMail/src/org/logicprobe/LogicMail/mail/smtp/SmtpClient.java
··· 223 223 this.password = password; 224 224 } 225 225 226 - public String sendMessage(MessageEnvelope envelope, Message message) 226 + public byte[] sendMessage(MessageEnvelope envelope, Message message) 227 227 throws IOException, MailException { 228 228 if (!isFresh) { 229 229 smtpProtocol.executeReset(); ··· 231 231 232 232 isFresh = false; 233 233 234 - // serialize the message 235 - MessageMimeConverter messageMime = new MessageMimeConverter(message); 234 + byte[] rawMessage = generateRawMessage(envelope, message); 236 235 237 - String mimeStr = messageMime.toMimeString(); 236 + sendEnvelopeInformation(envelope); 237 + 238 + // Send the message 239 + if (!smtpProtocol.executeData(rawMessage)) { 240 + throw new MailException("Error sending message"); 241 + } 238 242 239 - StringBuffer buffer = new StringBuffer(); 243 + return rawMessage; 244 + } 245 + 246 + private byte[] generateRawMessage(MessageEnvelope envelope, Message message) { 247 + // Serialize the message 248 + MessageMimeConverter messageMimeConverter = new MessageMimeConverter(message); 249 + 250 + // Generate the envelope headers 251 + byte[] messageHeaderData = MailMessageParser.generateMessageHeaders(envelope, true).getBytes(); 252 + 253 + // Generate the body headers and content 254 + byte[] messageMimeData = messageMimeConverter.toMimeByteArray(); 240 255 241 - // Generate the headers 242 - buffer.append(MailMessageParser.generateMessageHeaders(envelope, true)); 243 - 244 - // Add the body 245 - buffer.append(mimeStr); 256 + // Combine the two into the raw message 257 + byte[] rawMessage = new byte[messageHeaderData.length + messageMimeData.length]; 258 + System.arraycopy(messageHeaderData, 0, rawMessage, 0, messageHeaderData.length); 259 + System.arraycopy(messageMimeData, 0, rawMessage, messageHeaderData.length, messageMimeData.length); 260 + return rawMessage; 261 + } 246 262 247 - // Send the message 263 + private void sendEnvelopeInformation(MessageEnvelope envelope) 264 + throws IOException, MailException, RecipientException { 248 265 if (!smtpProtocol.executeMail(stripEmail(envelope.from[0]))) { 249 266 throw new MailException("Error with sender"); 250 267 } ··· 273 290 } 274 291 } 275 292 } 276 - 277 - String rawMessage = buffer.toString(); 278 - 279 - if (!smtpProtocol.executeData(rawMessage)) { 280 - throw new MailException("Error sending message"); 281 - } 282 - 283 - return rawMessage; 284 293 } 285 294 286 295 private static String stripEmail(String input) {
+29 -8
LogicMail/src/org/logicprobe/LogicMail/mail/smtp/SmtpProtocol.java
··· 42 42 import org.logicprobe.LogicMail.AppInfo; 43 43 import org.logicprobe.LogicMail.mail.MailException; 44 44 import org.logicprobe.LogicMail.util.Connection; 45 + import org.logicprobe.LogicMail.util.StringArrays; 45 46 import org.logicprobe.LogicMail.util.Watchdog; 46 47 47 48 /** ··· 296 297 297 298 /** 298 299 * Execute the "DATA" command. 299 - * @param message Message data fully serialized into a flat ASCII string 300 + * @param message Message data fully serialized into a flat ASCII byte array 300 301 * @return True if successful, false on failure 301 302 */ 302 - public boolean executeData(String message) throws IOException, MailException { 303 + public boolean executeData(byte[] message) throws IOException, MailException { 303 304 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 304 305 EventLogger.logEvent( 305 306 AppInfo.GUID, ··· 318 319 return false; 319 320 } 320 321 321 - byte[] data = message.getBytes(); 322 - for(int i=0; i<data.length; i+=1024) { 323 - connection.sendRaw(data, i, Math.min(1024, data.length - i)); 324 - watchdog.kick(); 322 + int offset = 0; 323 + while(offset < message.length) { 324 + int p = StringArrays.indexOf(message, CHAR_LF, offset); 325 + int len; 326 + if(p != -1) { 327 + len = (p + 1) - offset; 328 + } 329 + else { 330 + len = message.length - offset; 331 + } 332 + 333 + if(len == 0) { break; } 334 + if(message[offset] == CHAR_PERIOD) { 335 + byte[] escapedLine = new byte[len + 1]; 336 + escapedLine[0] = CHAR_PERIOD; 337 + System.arraycopy(message, offset, escapedLine, 1, len); 338 + connection.sendRaw(escapedLine, 0, escapedLine.length); 339 + } 340 + else { 341 + connection.sendRaw(message, offset, len); 342 + } 343 + watchdog.kick(); 344 + offset += len; 325 345 } 326 346 327 347 connection.sendCommand("\r\n."); 328 348 result = new String(connection.receive()); 329 - 330 349 watchdog.cancel(); 331 - 350 + 332 351 return result.startsWith(CODE_250); 333 352 } 334 353 ··· 498 517 private static String DATA = "DATA"; 499 518 private static String RSET = "RSET"; 500 519 private static String QUIT = "QUIT"; 520 + private static final byte CHAR_PERIOD = (byte)'.'; 521 + private static final byte CHAR_LF = (byte)'\n'; 501 522 }
+21 -4
LogicMail/src/org/logicprobe/LogicMail/message/MessageMimeConverter.java
··· 56 56 57 57 private MessageMimeConverterPartVisitor partVisitor; 58 58 59 + private boolean processed; 60 + 59 61 /** Creates a new instance of MessageMimeConverter */ 60 62 public MessageMimeConverter(Message message) { 61 63 this.message = message; ··· 67 69 68 70 /** 69 71 * Get the contents of this converter. 70 - * Due to the internal implementation, this method 71 - * may only be called once per instance. 72 72 * 73 73 * @return Message encoded in MIME format 74 74 */ 75 75 public String toMimeString() { 76 - message.getStructure().accept(partVisitor); 77 - partMimeMap.clear(); 76 + processMessage(); 78 77 return byteArrayOutputStream.toString(); 79 78 } 80 79 80 + /** 81 + * Get the contents of this converter. 82 + * 83 + * @return Message encoded in MIME format 84 + */ 85 + public byte[] toMimeByteArray() { 86 + processMessage(); 87 + return byteArrayOutputStream.toByteArray(); 88 + } 89 + 90 + private void processMessage() { 91 + if(!processed) { 92 + message.getStructure().accept(partVisitor); 93 + partMimeMap.clear(); 94 + processed = true; 95 + } 96 + } 97 + 81 98 private class MessageMimeConverterPartVisitor extends AbstractMimeMessagePartVisitor { 82 99 public void visitMultiPart(MultiPart part) { 83 100 MIMEOutputStream currentStream = startCurrentStream(part, null);
+8 -3
LogicMail/src/org/logicprobe/LogicMail/util/Connection.java
··· 296 296 * the processing done by the normal send method, and is most useful 297 297 * for bulk transmissions. It writes the provided string to the socket 298 298 * in a single command, followed by a flush. 299 + * 300 + * @param data the data. 301 + * @param offset the start offset in the data. 302 + * @param length the number of bytes to write. 299 303 * 300 304 * @see #send 301 305 */ 302 306 public void sendRaw(byte[] data, int offset, int length) throws IOException { 303 307 if (globalConfig.getConnDebug()) { 308 + ByteArrayOutputStream stream = new ByteArrayOutputStream(); 309 + stream.write("[SEND RAW]\r\n".getBytes()); 310 + stream.write(data, offset, length); 304 311 EventLogger.logEvent(AppInfo.GUID, 305 - ("[SEND RAW]\r\n" 306 - + new String(data, offset, length)).getBytes(), 307 - EventLogger.DEBUG_INFO); 312 + stream.toByteArray(), EventLogger.DEBUG_INFO); 308 313 } 309 314 310 315 synchronized(socketLock) {
+3
LogicMailTests/build.xml
··· 33 33 </rapc> 34 34 <property name="prebuild.jar" value="${dist.dir}/prebuild/${module.name}Prebuild.jar" /> 35 35 <property name="mocks.classpath" value="${prebuild.jar};${jde450.home}/lib/net_rim_api.jar" /> 36 + <hammockmaker usecldc11="true" dir="${tests.dir}/src" package="org.logicprobe.LogicMail.util" classpath="${mocks.classpath}"> 37 + <mock class="org.logicprobe.LogicMail.util.Connection" /> 38 + </hammockmaker> 36 39 <hammockmaker usecldc11="true" dir="${tests.dir}/src" package="org.logicprobe.LogicMail.mail" classpath="${mocks.classpath}"> 37 40 <mock class="org.logicprobe.LogicMail.mail.IncomingMailClient" /> 38 41 <mock class="org.logicprobe.LogicMail.mail.IncomingMailClientListener" />
+4
LogicMailTests/src/org/logicprobe/LogicMail/mail/MailTests.java
··· 34 34 import j2meunit.framework.TestCase; 35 35 import j2meunit.framework.TestSuite; 36 36 import org.logicprobe.LogicMail.mail.imap.ImapTests; 37 + import org.logicprobe.LogicMail.mail.pop.PopTests; 38 + import org.logicprobe.LogicMail.mail.smtp.SmtpTests; 37 39 38 40 /** 39 41 * Unit test suite for the LogicMail.mail classes ··· 48 50 TestSuite suite = new TestSuite("LogicMail.mail"); 49 51 suite.addTest(new NetworkMailStoreTest().suite()); 50 52 suite.addTest(new ImapTests().suite()); 53 + suite.addTest(new PopTests().suite()); 54 + suite.addTest(new SmtpTests().suite()); 51 55 return suite; 52 56 } 53 57 }
+229
LogicMailTests/src/org/logicprobe/LogicMail/mail/pop/PopProtocolTest.java
··· 1 + /*- 2 + * Copyright (c) 2011, Derek Konigsberg 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 8 + * 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of the project nor the names of its 15 + * contributors may be used to endorse or promote products derived 16 + * from this software without specific prior written permission. 17 + * 18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 + * OF THE POSSIBILITY OF SUCH DAMAGE. 30 + */ 31 + package org.logicprobe.LogicMail.mail.pop; 32 + 33 + import java.util.Hashtable; 34 + 35 + import org.logicprobe.LogicMail.conf.ConnectionConfig; 36 + import org.logicprobe.LogicMail.mail.MailException; 37 + import org.logicprobe.LogicMail.util.MockConnection; 38 + 39 + import com.hammingweight.hammock.Hammock; 40 + import com.hammingweight.hammock.mocks.microedition.io.MockSocketConnection; 41 + 42 + import j2meunit.framework.Test; 43 + import j2meunit.framework.TestCase; 44 + import j2meunit.framework.TestMethod; 45 + import j2meunit.framework.TestSuite; 46 + 47 + public class PopProtocolTest extends TestCase { 48 + private Hammock hammock; 49 + private PopProtocol instance; 50 + 51 + public PopProtocolTest() { 52 + } 53 + 54 + public PopProtocolTest(String testName, TestMethod testMethod) { 55 + super(testName, testMethod); 56 + } 57 + 58 + public void setUp() throws Exception { 59 + hammock = new Hammock(); 60 + instance = new PopProtocol(); 61 + 62 + MockSocketConnection socketConnection = new MockSocketConnection(hammock); 63 + hammock.setStubExpectation(MockSocketConnection.MTHD_OPEN_DATA_INPUT_STREAM).setReturnValue(null); 64 + hammock.setStubExpectation(MockSocketConnection.MTHD_OPEN_DATA_OUTPUT_STREAM).setReturnValue(null); 65 + hammock.setStubExpectation(MockSocketConnection.MTHD_GET_LOCAL_ADDRESS).setReturnValue(null); 66 + instance.setConnection(new MockConnection(socketConnection, ConnectionConfig.TRANSPORT_WIFI_ONLY, hammock)); 67 + 68 + hammock.setStubExpectation(MockConnection.MTHD_GET_BYTES_SENT).setReturnValue(new Integer(0)); 69 + hammock.setStubExpectation(MockConnection.MTHD_GET_BYTES_RECEIVED).setReturnValue(new Integer(0)); 70 + } 71 + 72 + public void tearDown() throws Exception { 73 + hammock.verify(); 74 + instance = null; 75 + } 76 + 77 + public void testExecuteUser() throws Throwable { 78 + expectCommand("USER testuser"); 79 + expectResponse("+OK Name is a valid mailbox"); 80 + 81 + instance.executeUser("testuser"); 82 + } 83 + 84 + public void testExecutePass() throws Throwable { 85 + expectCommand("PASS password"); 86 + expectResponse("+OK Mailbox locked and ready"); 87 + 88 + instance.executePass("password"); 89 + } 90 + 91 + public void testExecutePassInvalid() throws Throwable { 92 + expectCommand("PASS password"); 93 + expectResponse("-ERR [AUTH] Invalid login"); 94 + 95 + try { 96 + instance.executePass("password"); 97 + fail("Expected exception on authentication failure"); 98 + } catch (MailException e) { 99 + assertTrue(!e.isFatal()); 100 + } 101 + } 102 + 103 + public void testExecuteCapa() throws Throwable { 104 + expectCommand("CAPA"); 105 + expectResponse(new String[] { 106 + "+OK List of capabilities follows", 107 + "EXPIRE NEVER", 108 + "TOP", 109 + "." 110 + }); 111 + 112 + Hashtable result = instance.executeCapa(); 113 + assertNotNull(result); 114 + assertEquals(2, result.size()); 115 + assertEquals("NEVER", result.get("EXPIRE")); 116 + assertEquals(Boolean.TRUE, result.get("TOP")); 117 + } 118 + 119 + public void testExecuteCapaUnsupported() throws Throwable { 120 + expectCommand("CAPA"); 121 + expectResponse("-ERR Unrecognized command"); 122 + 123 + Hashtable result = instance.executeCapa(); 124 + assertNull(result); 125 + } 126 + 127 + public void testExecuteRetr() throws Throwable { 128 + expectCommand("RETR 1"); 129 + String[] expected = new String[] { 130 + "+OK Message follows", 131 + "Date: Sat, 2 Aug 2008 10:19:55 -0400 (EDT)", 132 + "From: Foo Bar <foobar@test.org>", 133 + "To: barfoo@test.net", 134 + "Subject: Test Message", 135 + "Content-Type: text/plain; charset=US-ASCII; format=flowed", 136 + "", 137 + "This is the message content", 138 + "", 139 + "." 140 + }; 141 + expectResponse(expected); 142 + 143 + byte[][] response = instance.executeRetr(1, null); 144 + 145 + assertFollowsEquals(expected, response); 146 + } 147 + 148 + public void testExecuteRetrEscapedDots() throws Throwable { 149 + expectCommand("RETR 1"); 150 + String[] expected = new String[] { 151 + "+OK Message follows", 152 + "Date: Sat, 2 Aug 2008 10:19:55 -0400 (EDT)", 153 + "From: Foo Bar <foobar@test.org>", 154 + "To: barfoo@test.net", 155 + "Subject: Test Message", 156 + "Content-Type: text/plain; charset=US-ASCII; format=flowed", 157 + "", 158 + "This is the message content", 159 + "....", 160 + "...", 161 + "..", 162 + "", 163 + "." 164 + }; 165 + expectResponse(copyArray(expected)); 166 + expected[8] = "..."; 167 + expected[9] = ".."; 168 + expected[10] = "."; 169 + 170 + 171 + byte[][] response = instance.executeRetr(1, null); 172 + 173 + assertFollowsEquals(expected, response); 174 + } 175 + 176 + private static String[] copyArray(String[] input) { 177 + if(input == null || input.length == 0) { return input; } 178 + 179 + String[] result = new String[input.length]; 180 + System.arraycopy(input, 0, result, 0, input.length); 181 + return result; 182 + } 183 + 184 + private void assertFollowsEquals(String[] expected, byte[][] response) { 185 + assertNotNull(response); 186 + assertEquals(expected.length - 2, response.length); 187 + for(int i=0; i<response.length; i++) { 188 + assertEquals(expected[i + 1], new String(response[i])); 189 + } 190 + } 191 + 192 + private void expectCommand(String command) { 193 + hammock.setExpectation(MockConnection.MTHD_SEND_COMMAND_$_STRING, 194 + new Object[] { command }); 195 + } 196 + 197 + private void expectResponse(String response) { 198 + hammock.setExpectation(MockConnection.MTHD_RECEIVE) 199 + .setReturnValue(response.getBytes()); 200 + } 201 + 202 + private void expectResponse(String[] response) { 203 + for(int i=0; i<response.length; i++) { 204 + hammock.setExpectation(MockConnection.MTHD_RECEIVE) 205 + .setReturnValue(response[i].getBytes()); 206 + } 207 + } 208 + 209 + public Test suite() { 210 + TestSuite suite = new TestSuite("PopProtocol"); 211 + 212 + suite.addTest(new PopProtocolTest("executeUser", new TestMethod() 213 + { public void run(TestCase tc) throws Throwable { ((PopProtocolTest)tc).testExecuteUser(); }})); 214 + suite.addTest(new PopProtocolTest("executePass", new TestMethod() 215 + { public void run(TestCase tc) throws Throwable { ((PopProtocolTest)tc).testExecutePass(); }})); 216 + suite.addTest(new PopProtocolTest("executePassInvalid", new TestMethod() 217 + { public void run(TestCase tc) throws Throwable { ((PopProtocolTest)tc).testExecutePassInvalid(); }})); 218 + suite.addTest(new PopProtocolTest("executeCapa", new TestMethod() 219 + { public void run(TestCase tc) throws Throwable { ((PopProtocolTest)tc).testExecuteCapa(); }})); 220 + suite.addTest(new PopProtocolTest("executeCapaUnsupported", new TestMethod() 221 + { public void run(TestCase tc) throws Throwable { ((PopProtocolTest)tc).testExecuteCapaUnsupported(); }})); 222 + suite.addTest(new PopProtocolTest("executeRetr", new TestMethod() 223 + { public void run(TestCase tc) throws Throwable { ((PopProtocolTest)tc).testExecuteRetr(); }})); 224 + suite.addTest(new PopProtocolTest("executeRetrEscapedDots", new TestMethod() 225 + { public void run(TestCase tc) throws Throwable { ((PopProtocolTest)tc).testExecuteRetrEscapedDots(); }})); 226 + 227 + return suite; 228 + } 229 + }
+48
LogicMailTests/src/org/logicprobe/LogicMail/mail/pop/PopTests.java
··· 1 + /*- 2 + * Copyright (c) 2011, Derek Konigsberg 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 8 + * 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of the project nor the names of its 15 + * contributors may be used to endorse or promote products derived 16 + * from this software without specific prior written permission. 17 + * 18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 + * OF THE POSSIBILITY OF SUCH DAMAGE. 30 + */ 31 + package org.logicprobe.LogicMail.mail.pop; 32 + 33 + import j2meunit.framework.Test; 34 + import j2meunit.framework.TestCase; 35 + import j2meunit.framework.TestSuite; 36 + 37 + public class PopTests extends TestCase { 38 + 39 + public PopTests() { 40 + super(); 41 + } 42 + 43 + public Test suite() { 44 + TestSuite suite = new TestSuite("LogicMail.mail.pop"); 45 + suite.addTest(new PopProtocolTest().suite()); 46 + return suite; 47 + } 48 + }
+245
LogicMailTests/src/org/logicprobe/LogicMail/mail/smtp/SmtpProtocolTest.java
··· 1 + /*- 2 + * Copyright (c) 2011, Derek Konigsberg 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 8 + * 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of the project nor the names of its 15 + * contributors may be used to endorse or promote products derived 16 + * from this software without specific prior written permission. 17 + * 18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 + * OF THE POSSIBILITY OF SUCH DAMAGE. 30 + */ 31 + package org.logicprobe.LogicMail.mail.smtp; 32 + 33 + import java.io.ByteArrayOutputStream; 34 + import java.io.IOException; 35 + 36 + import net.rim.device.api.util.Arrays; 37 + 38 + import org.logicprobe.LogicMail.conf.ConnectionConfig; 39 + import org.logicprobe.LogicMail.util.MockConnection; 40 + 41 + import com.hammingweight.hammock.Hammock; 42 + import com.hammingweight.hammock.IArgumentMatcher; 43 + import com.hammingweight.hammock.mocks.microedition.io.MockSocketConnection; 44 + 45 + import j2meunit.framework.Test; 46 + import j2meunit.framework.TestCase; 47 + import j2meunit.framework.TestMethod; 48 + import j2meunit.framework.TestSuite; 49 + 50 + public class SmtpProtocolTest extends TestCase { 51 + private Hammock hammock; 52 + private SmtpProtocol instance; 53 + 54 + public SmtpProtocolTest() { 55 + } 56 + 57 + public SmtpProtocolTest(String testName, TestMethod testMethod) { 58 + super(testName, testMethod); 59 + } 60 + 61 + public void setUp() throws Exception { 62 + hammock = new Hammock(); 63 + instance = new SmtpProtocol(); 64 + 65 + MockSocketConnection socketConnection = new MockSocketConnection(hammock); 66 + hammock.setStubExpectation(MockSocketConnection.MTHD_OPEN_DATA_INPUT_STREAM).setReturnValue(null); 67 + hammock.setStubExpectation(MockSocketConnection.MTHD_OPEN_DATA_OUTPUT_STREAM).setReturnValue(null); 68 + hammock.setStubExpectation(MockSocketConnection.MTHD_GET_LOCAL_ADDRESS).setReturnValue(null); 69 + instance.setConnection(new MockConnection(socketConnection, ConnectionConfig.TRANSPORT_WIFI_ONLY, hammock)); 70 + 71 + hammock.setStubExpectation(MockConnection.MTHD_GET_BYTES_SENT).setReturnValue(new Integer(0)); 72 + hammock.setStubExpectation(MockConnection.MTHD_GET_BYTES_RECEIVED).setReturnValue(new Integer(0)); 73 + } 74 + 75 + public void tearDown() throws Exception { 76 + hammock.verify(); 77 + instance = null; 78 + } 79 + 80 + public void testExecuteAuthPlain() throws Throwable { 81 + // Base64 encoded: "\000username\000password" 82 + expectCommand("AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk"); 83 + expectResponse("235 ok, go ahead"); 84 + 85 + boolean result = instance.executeAuth(SmtpProtocol.AUTH_PLAIN, "username", "password"); 86 + assertTrue(result); 87 + } 88 + 89 + public void testExecuteAuthPlainFailed() throws Throwable { 90 + // Base64 encoded: "\000username\000password" 91 + expectCommand("AUTH PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk"); 92 + expectResponse("535 authorization failed"); 93 + 94 + boolean result = instance.executeAuth(SmtpProtocol.AUTH_PLAIN, "username", "password"); 95 + assertTrue(!result); 96 + } 97 + 98 + public void testExecuteData() throws Throwable { 99 + expectCommand("DATA"); 100 + expectResponse("354 Enter mail, end with \".\" on a line by itself"); 101 + String[] rawMessage = new String[] { 102 + "Date: Sat, 2 Aug 2008 10:19:55 -0400 (EDT)\r\n", 103 + "From: Foo Bar <foobar@test.org>\r\n", 104 + "To: barfoo@test.net\r\n", 105 + "Subject: Test Message\r\n", 106 + "Content-Type: text/plain; charset=US-ASCII; format=flowed\r\n", 107 + "\r\n", 108 + "This is the message content\r\n", 109 + }; 110 + expectRawSmtpData(rawMessage); 111 + expectCommand("\r\n."); 112 + expectResponse("250 2.0.0 p6SJXCeA015681 Message accepted for delivery"); 113 + boolean result = instance.executeData(toByteArray(rawMessage)); 114 + 115 + assertTrue(result); 116 + } 117 + 118 + public void testExecuteDataEmpty() throws Throwable { 119 + expectCommand("DATA"); 120 + expectResponse("354 Enter mail, end with \".\" on a line by itself"); 121 + expectCommand("\r\n."); 122 + expectResponse("250 2.0.0 p6SJXCeA015681 Message accepted for delivery"); 123 + boolean result = instance.executeData(new byte[0]); 124 + 125 + assertTrue(result); 126 + } 127 + 128 + public void testExecuteDataAlmostEmpty() throws Throwable { 129 + expectCommand("DATA"); 130 + expectResponse("354 Enter mail, end with \".\" on a line by itself"); 131 + String[] rawMessage = new String[] { 132 + "\r\n" 133 + }; 134 + expectRawSmtpData(rawMessage); 135 + expectCommand("\r\n."); 136 + expectResponse("250 2.0.0 p6SJXCeA015681 Message accepted for delivery"); 137 + boolean result = instance.executeData(toByteArray(rawMessage)); 138 + 139 + assertTrue(result); 140 + } 141 + 142 + public void testExecuteDataWithDots() throws Throwable { 143 + expectCommand("DATA"); 144 + expectResponse("354 Enter mail, end with \".\" on a line by itself"); 145 + String[] rawMessage = new String[] { 146 + "Date: Sat, 2 Aug 2008 10:19:55 -0400 (EDT)\r\n", 147 + "From: Foo Bar <foobar@test.org>\r\n", 148 + "To: barfoo@test.net\r\n", 149 + "Subject: Test Message\r\n", 150 + "Content-Type: text/plain; charset=US-ASCII; format=flowed\r\n", 151 + "\r\n", 152 + "This is the message content\r\n", 153 + "...\r\n", 154 + "..\r\n", 155 + ".\r\n" 156 + }; 157 + String[] expectedData = copyArray(rawMessage); 158 + expectedData[7] = "." + expectedData[7]; 159 + expectedData[8] = "." + expectedData[8]; 160 + expectedData[9] = "." + expectedData[9]; 161 + expectRawSmtpData(expectedData); 162 + expectCommand("\r\n."); 163 + expectResponse("250 2.0.0 p6SJXCeA015681 Message accepted for delivery"); 164 + boolean result = instance.executeData(toByteArray(rawMessage)); 165 + 166 + assertTrue(result); 167 + } 168 + 169 + private void expectCommand(String command) { 170 + hammock.setExpectation(MockConnection.MTHD_SEND_COMMAND_$_STRING, 171 + new Object[] { command }); 172 + } 173 + 174 + private void expectResponse(String response) { 175 + hammock.setExpectation(MockConnection.MTHD_RECEIVE) 176 + .setReturnValue(response.getBytes()); 177 + } 178 + 179 + private void expectRawSmtpData(String[] data) { 180 + int offset = 0; 181 + for(int i=0; i<data.length; i++) { 182 + byte[] line = data[i].getBytes(); 183 + if(line[0] == (byte)'.') { 184 + hammock.setExpectation(MockConnection.MTHD_SEND_RAW_$_ARRAY_BYTE_INT_INT, 185 + new Object[] { line, new Integer(0), new Integer(line.length) } ); 186 + offset += line.length - 1; 187 + } 188 + else { 189 + hammock.setExpectation(MockConnection.MTHD_SEND_RAW_$_ARRAY_BYTE_INT_INT, 190 + new Object[] { line, new Integer(offset), new Integer(line.length) } ) 191 + .setArgumentMatcher(0, new ArrayOffsetArgumentMatcher(offset, line.length)); 192 + offset += line.length; 193 + } 194 + } 195 + } 196 + 197 + private static class ArrayOffsetArgumentMatcher implements IArgumentMatcher { 198 + private final int offset; 199 + private final int length; 200 + public ArrayOffsetArgumentMatcher(int offset, int length) { 201 + this.offset = offset; 202 + this.length = length; 203 + } 204 + public boolean areArgumentsEqual(Object argumentExpected, Object argumentActual) { 205 + byte[] expected = (byte[])argumentExpected; 206 + byte[] actual = (byte[])argumentActual; 207 + return Arrays.equals(expected, 0, actual, offset, length); 208 + } 209 + } 210 + 211 + private static byte[] toByteArray(String[] stringData) throws IOException { 212 + ByteArrayOutputStream stream = new ByteArrayOutputStream(); 213 + for(int i=0; i<stringData.length; i++) { 214 + stream.write(stringData[i].getBytes()); 215 + } 216 + return stream.toByteArray(); 217 + } 218 + 219 + private static String[] copyArray(String[] input) { 220 + if(input == null || input.length == 0) { return input; } 221 + 222 + String[] result = new String[input.length]; 223 + System.arraycopy(input, 0, result, 0, input.length); 224 + return result; 225 + } 226 + 227 + public Test suite() { 228 + TestSuite suite = new TestSuite("SmtpProtocol"); 229 + 230 + suite.addTest(new SmtpProtocolTest("executeAuthPlain", new TestMethod() 231 + { public void run(TestCase tc) throws Throwable { ((SmtpProtocolTest)tc).testExecuteAuthPlain(); }})); 232 + suite.addTest(new SmtpProtocolTest("executeAuthPlainFailed", new TestMethod() 233 + { public void run(TestCase tc) throws Throwable { ((SmtpProtocolTest)tc).testExecuteAuthPlainFailed(); }})); 234 + suite.addTest(new SmtpProtocolTest("executeData", new TestMethod() 235 + { public void run(TestCase tc) throws Throwable { ((SmtpProtocolTest)tc).testExecuteData(); }})); 236 + suite.addTest(new SmtpProtocolTest("executeDataEmpty", new TestMethod() 237 + { public void run(TestCase tc) throws Throwable { ((SmtpProtocolTest)tc).testExecuteDataEmpty(); }})); 238 + suite.addTest(new SmtpProtocolTest("executeDataAlmostEmpty", new TestMethod() 239 + { public void run(TestCase tc) throws Throwable { ((SmtpProtocolTest)tc).testExecuteDataAlmostEmpty(); }})); 240 + suite.addTest(new SmtpProtocolTest("executeDataWithDots", new TestMethod() 241 + { public void run(TestCase tc) throws Throwable { ((SmtpProtocolTest)tc).testExecuteDataWithDots(); }})); 242 + 243 + return suite; 244 + } 245 + }
+48
LogicMailTests/src/org/logicprobe/LogicMail/mail/smtp/SmtpTests.java
··· 1 + /*- 2 + * Copyright (c) 2011, Derek Konigsberg 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions 7 + * are met: 8 + * 9 + * 1. Redistributions of source code must retain the above copyright 10 + * notice, this list of conditions and the following disclaimer. 11 + * 2. Redistributions in binary form must reproduce the above copyright 12 + * notice, this list of conditions and the following disclaimer in the 13 + * documentation and/or other materials provided with the distribution. 14 + * 3. Neither the name of the project nor the names of its 15 + * contributors may be used to endorse or promote products derived 16 + * from this software without specific prior written permission. 17 + * 18 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 27 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 29 + * OF THE POSSIBILITY OF SUCH DAMAGE. 30 + */ 31 + package org.logicprobe.LogicMail.mail.smtp; 32 + 33 + import j2meunit.framework.Test; 34 + import j2meunit.framework.TestCase; 35 + import j2meunit.framework.TestSuite; 36 + 37 + public class SmtpTests extends TestCase { 38 + 39 + public SmtpTests() { 40 + super(); 41 + } 42 + 43 + public Test suite() { 44 + TestSuite suite = new TestSuite("LogicMail.mail.smtp"); 45 + suite.addTest(new SmtpProtocolTest().suite()); 46 + return suite; 47 + } 48 + }
+368
LogicMailTests/src/org/logicprobe/LogicMail/util/MockConnection.java
··· 1 + /* 2 + * This source code was generated by HammockMaker. 3 + * It should be used with the Hammock libraries for the 4 + * CLDC 1.1 configuration. 5 + */ 6 + package org.logicprobe.LogicMail.util; 7 + 8 + import com.hammingweight.hammock.*; 9 + 10 + public class MockConnection extends org.logicprobe.LogicMail.util.Connection implements IMockObject { 11 + 12 + private IInvocationHandler handler; 13 + 14 + // Methods defined in IMockObject. 15 + public final void setInvocationHandler(IInvocationHandler handler) { 16 + if (handler == null) { 17 + throw new NullPointerException(); 18 + } 19 + 20 + this.handler = handler; 21 + } 22 + 23 + public final IInvocationHandler getInvocationHandler() { 24 + if (this.handler == null) { 25 + setInvocationHandler(new Hamspy()); 26 + } 27 + return this.handler; 28 + } 29 + 30 + // Overridden methods. 31 + public static final MockMethod MTHD_AVAILABLE = new MockMethod( 32 + MockConnection.class, 33 + "MTHD_AVAILABLE", 34 + new Class[]{}, 35 + new Class[]{java.io.IOException.class}, 36 + Integer.class, 37 + false); 38 + public int available() throws java.io.IOException { 39 + try { 40 + Object[] args = new Object[0]; 41 + MethodInvocation mi = new MethodInvocation(MTHD_AVAILABLE, this, args); 42 + getInvocationHandler().invoke(mi); 43 + if (mi.isEvaluated()) { 44 + Object retVal = mi.getReturnValue(); 45 + AMockObject.assertReturnNotNull(MTHD_AVAILABLE, retVal); 46 + return ((Integer)retVal).intValue(); 47 + } 48 + } catch (Throwable t) { 49 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 50 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 51 + if (t instanceof java.io.IOException) { throw (java.io.IOException)t; } 52 + throw new HammockException(t); 53 + } 54 + return super.available(); 55 + } 56 + 57 + public static final MockMethod MTHD_CLOSE = new MockMethod( 58 + MockConnection.class, 59 + "MTHD_CLOSE", 60 + new Class[]{}, 61 + new Class[]{}, 62 + null, 63 + false); 64 + public void close() { 65 + try { 66 + Object[] args = new Object[0]; 67 + MethodInvocation mi = new MethodInvocation(MTHD_CLOSE, this, args); 68 + getInvocationHandler().invoke(mi); 69 + if (mi.isEvaluated()) { 70 + mi.getReturnValue(); 71 + return; 72 + } 73 + } catch (Throwable t) { 74 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 75 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 76 + throw new HammockException(t); 77 + } 78 + super.close(); 79 + } 80 + 81 + public static final MockMethod MTHD_ENABLE_COMPRESSION = new MockMethod( 82 + MockConnection.class, 83 + "MTHD_ENABLE_COMPRESSION", 84 + new Class[]{}, 85 + new Class[]{}, 86 + null, 87 + false); 88 + public void enableCompression() { 89 + try { 90 + Object[] args = new Object[0]; 91 + MethodInvocation mi = new MethodInvocation(MTHD_ENABLE_COMPRESSION, this, args); 92 + getInvocationHandler().invoke(mi); 93 + if (mi.isEvaluated()) { 94 + mi.getReturnValue(); 95 + return; 96 + } 97 + } catch (Throwable t) { 98 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 99 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 100 + throw new HammockException(t); 101 + } 102 + super.enableCompression(); 103 + } 104 + 105 + public static final MockMethod MTHD_FORCE_CLOSE = new MockMethod( 106 + MockConnection.class, 107 + "MTHD_FORCE_CLOSE", 108 + new Class[]{}, 109 + new Class[]{}, 110 + null, 111 + false); 112 + public void forceClose() { 113 + try { 114 + Object[] args = new Object[0]; 115 + MethodInvocation mi = new MethodInvocation(MTHD_FORCE_CLOSE, this, args); 116 + getInvocationHandler().invoke(mi); 117 + if (mi.isEvaluated()) { 118 + mi.getReturnValue(); 119 + return; 120 + } 121 + } catch (Throwable t) { 122 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 123 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 124 + throw new HammockException(t); 125 + } 126 + super.forceClose(); 127 + } 128 + 129 + public static final MockMethod MTHD_GET_BYTES_RECEIVED = new MockMethod( 130 + MockConnection.class, 131 + "MTHD_GET_BYTES_RECEIVED", 132 + new Class[]{}, 133 + new Class[]{}, 134 + Integer.class, 135 + false); 136 + public int getBytesReceived() { 137 + try { 138 + Object[] args = new Object[0]; 139 + MethodInvocation mi = new MethodInvocation(MTHD_GET_BYTES_RECEIVED, this, args); 140 + getInvocationHandler().invoke(mi); 141 + if (mi.isEvaluated()) { 142 + Object retVal = mi.getReturnValue(); 143 + AMockObject.assertReturnNotNull(MTHD_GET_BYTES_RECEIVED, retVal); 144 + return ((Integer)retVal).intValue(); 145 + } 146 + } catch (Throwable t) { 147 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 148 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 149 + throw new HammockException(t); 150 + } 151 + return super.getBytesReceived(); 152 + } 153 + 154 + public static final MockMethod MTHD_GET_BYTES_SENT = new MockMethod( 155 + MockConnection.class, 156 + "MTHD_GET_BYTES_SENT", 157 + new Class[]{}, 158 + new Class[]{}, 159 + Integer.class, 160 + false); 161 + public int getBytesSent() { 162 + try { 163 + Object[] args = new Object[0]; 164 + MethodInvocation mi = new MethodInvocation(MTHD_GET_BYTES_SENT, this, args); 165 + getInvocationHandler().invoke(mi); 166 + if (mi.isEvaluated()) { 167 + Object retVal = mi.getReturnValue(); 168 + AMockObject.assertReturnNotNull(MTHD_GET_BYTES_SENT, retVal); 169 + return ((Integer)retVal).intValue(); 170 + } 171 + } catch (Throwable t) { 172 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 173 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 174 + throw new HammockException(t); 175 + } 176 + return super.getBytesSent(); 177 + } 178 + 179 + public static final MockMethod MTHD_GET_CONNECTION_TYPE = new MockMethod( 180 + MockConnection.class, 181 + "MTHD_GET_CONNECTION_TYPE", 182 + new Class[]{}, 183 + new Class[]{}, 184 + Integer.class, 185 + false); 186 + public int getConnectionType() { 187 + try { 188 + Object[] args = new Object[0]; 189 + MethodInvocation mi = new MethodInvocation(MTHD_GET_CONNECTION_TYPE, this, args); 190 + getInvocationHandler().invoke(mi); 191 + if (mi.isEvaluated()) { 192 + Object retVal = mi.getReturnValue(); 193 + AMockObject.assertReturnNotNull(MTHD_GET_CONNECTION_TYPE, retVal); 194 + return ((Integer)retVal).intValue(); 195 + } 196 + } catch (Throwable t) { 197 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 198 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 199 + throw new HammockException(t); 200 + } 201 + return super.getConnectionType(); 202 + } 203 + 204 + public static final MockMethod MTHD_GET_LOCAL_ADDRESS = new MockMethod( 205 + MockConnection.class, 206 + "MTHD_GET_LOCAL_ADDRESS", 207 + new Class[]{}, 208 + new Class[]{}, 209 + java.lang.String.class, 210 + false); 211 + public java.lang.String getLocalAddress() { 212 + try { 213 + Object[] args = new Object[0]; 214 + MethodInvocation mi = new MethodInvocation(MTHD_GET_LOCAL_ADDRESS, this, args); 215 + getInvocationHandler().invoke(mi); 216 + if (mi.isEvaluated()) { 217 + Object retVal = mi.getReturnValue(); 218 + return (java.lang.String)retVal; 219 + } 220 + } catch (Throwable t) { 221 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 222 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 223 + throw new HammockException(t); 224 + } 225 + return super.getLocalAddress(); 226 + } 227 + 228 + public static final MockMethod MTHD_IS_CONNECTED = new MockMethod( 229 + MockConnection.class, 230 + "MTHD_IS_CONNECTED", 231 + new Class[]{}, 232 + new Class[]{}, 233 + Boolean.class, 234 + false); 235 + public boolean isConnected() { 236 + try { 237 + Object[] args = new Object[0]; 238 + MethodInvocation mi = new MethodInvocation(MTHD_IS_CONNECTED, this, args); 239 + getInvocationHandler().invoke(mi); 240 + if (mi.isEvaluated()) { 241 + Object retVal = mi.getReturnValue(); 242 + AMockObject.assertReturnNotNull(MTHD_IS_CONNECTED, retVal); 243 + return ((Boolean)retVal).booleanValue(); 244 + } 245 + } catch (Throwable t) { 246 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 247 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 248 + throw new HammockException(t); 249 + } 250 + return super.isConnected(); 251 + } 252 + 253 + public static final MockMethod MTHD_RECEIVE = new MockMethod( 254 + MockConnection.class, 255 + "MTHD_RECEIVE", 256 + new Class[]{}, 257 + new Class[]{java.io.IOException.class}, 258 + byte[].class, 259 + false); 260 + public byte[] receive() throws java.io.IOException { 261 + try { 262 + Object[] args = new Object[0]; 263 + MethodInvocation mi = new MethodInvocation(MTHD_RECEIVE, this, args); 264 + getInvocationHandler().invoke(mi); 265 + if (mi.isEvaluated()) { 266 + Object retVal = mi.getReturnValue(); 267 + return (byte[])retVal; 268 + } 269 + } catch (Throwable t) { 270 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 271 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 272 + if (t instanceof java.io.IOException) { throw (java.io.IOException)t; } 273 + throw new HammockException(t); 274 + } 275 + return super.receive(); 276 + } 277 + 278 + public static final MockMethod MTHD_RECEIVE_$_CONNECTIONRESPONSETESTER = new MockMethod( 279 + MockConnection.class, 280 + "MTHD_RECEIVE_$_CONNECTIONRESPONSETESTER", 281 + new Class[]{org.logicprobe.LogicMail.util.ConnectionResponseTester.class}, 282 + new Class[]{java.io.IOException.class}, 283 + byte[].class, 284 + false); 285 + public byte[] receive(org.logicprobe.LogicMail.util.ConnectionResponseTester arg0) throws java.io.IOException { 286 + try { 287 + Object[] args = new Object[1]; 288 + args[0] = arg0; 289 + MethodInvocation mi = new MethodInvocation(MTHD_RECEIVE_$_CONNECTIONRESPONSETESTER, this, args); 290 + getInvocationHandler().invoke(mi); 291 + if (mi.isEvaluated()) { 292 + Object retVal = mi.getReturnValue(); 293 + return (byte[])retVal; 294 + } 295 + } catch (Throwable t) { 296 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 297 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 298 + if (t instanceof java.io.IOException) { throw (java.io.IOException)t; } 299 + throw new HammockException(t); 300 + } 301 + return super.receive(arg0); 302 + } 303 + 304 + public static final MockMethod MTHD_SEND_COMMAND_$_STRING = new MockMethod( 305 + MockConnection.class, 306 + "MTHD_SEND_COMMAND_$_STRING", 307 + new Class[]{java.lang.String.class}, 308 + new Class[]{java.io.IOException.class}, 309 + null, 310 + false); 311 + public void sendCommand(java.lang.String arg0) throws java.io.IOException { 312 + try { 313 + Object[] args = new Object[1]; 314 + args[0] = arg0; 315 + MethodInvocation mi = new MethodInvocation(MTHD_SEND_COMMAND_$_STRING, this, args); 316 + getInvocationHandler().invoke(mi); 317 + if (mi.isEvaluated()) { 318 + mi.getReturnValue(); 319 + return; 320 + } 321 + } catch (Throwable t) { 322 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 323 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 324 + if (t instanceof java.io.IOException) { throw (java.io.IOException)t; } 325 + throw new HammockException(t); 326 + } 327 + super.sendCommand(arg0); 328 + } 329 + 330 + public static final MockMethod MTHD_SEND_RAW_$_ARRAY_BYTE_INT_INT = new MockMethod( 331 + MockConnection.class, 332 + "MTHD_SEND_RAW_$_ARRAY_BYTE_INT_INT", 333 + new Class[]{byte[].class, Integer.class, Integer.class}, 334 + new Class[]{java.io.IOException.class}, 335 + null, 336 + false); 337 + public void sendRaw(byte[] arg0, int arg1, int arg2) throws java.io.IOException { 338 + try { 339 + Object[] args = new Object[3]; 340 + args[0] = arg0; 341 + args[1] = new Integer(arg1); 342 + args[2] = new Integer(arg2); 343 + MethodInvocation mi = new MethodInvocation(MTHD_SEND_RAW_$_ARRAY_BYTE_INT_INT, this, args); 344 + getInvocationHandler().invoke(mi); 345 + if (mi.isEvaluated()) { 346 + mi.getReturnValue(); 347 + return; 348 + } 349 + } catch (Throwable t) { 350 + if (t instanceof java.lang.Error) { throw (java.lang.Error)t; } 351 + if (t instanceof java.lang.RuntimeException) { throw (java.lang.RuntimeException)t; } 352 + if (t instanceof java.io.IOException) { throw (java.io.IOException)t; } 353 + throw new HammockException(t); 354 + } 355 + super.sendRaw(arg0, arg1, arg2); 356 + } 357 + 358 + // Constructors. 359 + public MockConnection(javax.microedition.io.SocketConnection arg0, int arg1) throws java.io.IOException { 360 + super(arg0, arg1); 361 + } 362 + 363 + public MockConnection(javax.microedition.io.SocketConnection arg0, int arg1, IInvocationHandler handler) throws java.io.IOException { 364 + super(arg0, arg1); 365 + setInvocationHandler(handler); 366 + } 367 + 368 + }