Methods Summary |
---|
public boolean | canTrySslSecurity()
return (mConnectionSecurity == CONNECTION_SECURITY_SSL_REQUIRED
|| mConnectionSecurity == CONNECTION_SECURITY_SSL_OPTIONAL);
|
public boolean | canTryTlsSecurity()
return (mConnectionSecurity == Transport.CONNECTION_SECURITY_TLS_OPTIONAL
|| mConnectionSecurity == Transport.CONNECTION_SECURITY_TLS_REQUIRED);
|
public void | close()
mOpen = false;
mInputOpen = false;
// unless it was expected as part of a test, reset the stream
if (mPairs.size() > 0) {
Transaction expect = mPairs.remove(0);
if (expect.mAction == Transaction.ACTION_CLIENT_CLOSE) {
return;
}
}
mQueuedInput.clear();
mPairs.clear();
|
public void | closeInputStream()This simulates a condition where the server has closed its side, causing
reads to fail.
mInputOpen = false;
|
public void | expect(java.lang.String pattern, java.lang.String response)Give the mock a pattern to wait for and a response to send back.
expect(pattern, (response == null) ? null : new String[] { response });
|
public void | expect(java.lang.String pattern, java.lang.String[] responses)Give the mock a pattern to wait for and a multi-line response to send back.
Transaction pair = new Transaction(pattern, responses);
mPairs.add(pair);
|
public void | expectClose()Tell the Mock Transport that we expect it to be closed. This will preserve
the remaining entries in the expect() stream and allow us to "ride over" the close (which
would normally reset everything).
mPairs.add(new Transaction(Transaction.ACTION_CLIENT_CLOSE));
|
public java.lang.String | getHost()
SmtpSenderUnitTests.fail("getHost() not implemented");
return null;
|
public java.io.InputStream | getInputStream()
SmtpSenderUnitTests.assertTrue(mOpen);
return new MockInputStream();
|
public java.io.OutputStream | getOutputStream()
SmtpSenderUnitTests.assertTrue(mOpen);
return new MockOutputStream();
|
public int | getPort()
SmtpSenderUnitTests.fail("getPort() not implemented");
return 0;
|
public int | getSecurity()
return mConnectionSecurity;
|
public java.lang.String[] | getUserInfoParts()
SmtpSenderUnitTests.fail("getUserInfoParts() not implemented");
return null;
|
public boolean | isOpen()
return mOpen;
|
public com.android.email.mail.Transport | newInstanceWithConfiguration()This normally serves as a pseudo-clone, for use by Imap. For the purposes of unit testing,
until we need something more complex, we'll just return the actual MockTransport. Then we
don't have to worry about dealing with test metadata like the expects list or socket state.
return this;
|
public void | open()
mOpen = true;
mInputOpen = true;
|
public java.lang.String | readLine()This returns one string (if available) to the caller. Usually this simply pulls strings
from the mQueuedInput list, but if the list is empty, we also peek the expect list. This
supports banners, multi-line responses, and any other cases where we respond without
a specific expect pattern.
If no response text is available, we assert (failing our test) as an underflow.
Logs the read text if DEBUG_LOG_STREAMS is true.
SmtpSenderUnitTests.assertTrue(mOpen);
if (!mInputOpen) {
throw new IOException("Reading from MockTransport with closed input");
}
// if there's nothing to read, see if we can find a null-pattern response
if (0 == mQueuedInput.size()) {
Transaction pair = mPairs.get(0);
if (pair != null && pair.mPattern == null) {
mPairs.remove(0);
sendResponse(pair.mResponses);
}
}
SmtpSenderUnitTests.assertTrue("Underflow reading from MockTransport", 0 != mQueuedInput.size());
String line = mQueuedInput.remove(0);
if (DEBUG_LOG_STREAMS) {
Log.d(LOG_TAG, "<<< " + line);
}
return line;
|
public void | reopenTls()
SmtpSenderUnitTests.assertTrue(mOpen);
SmtpSenderUnitTests.assertTrue(mTlsAllowed);
SmtpSenderUnitTests.fail("reopenTls() not implemented");
|
private void | sendResponse(java.lang.String[] responses)
for (String s : responses) {
mQueuedInput.add(s);
}
|
public void | setSecurity(int connectionSecurity)
mConnectionSecurity = connectionSecurity;
|
public void | setSoTimeout(int timeoutMilliseconds)
|
public void | setUri(java.net.URI uri, int defaultPort)
SmtpSenderUnitTests.assertTrue("Don't call setUri on a mock transport", false);
|
public void | writeLine(java.lang.String s, java.lang.String sensitiveReplacement)Accepts a single string (command or text) that was written by the code under test.
Because we are essentially mocking a server, we check to see if this string was expected.
If the string was expected, we push the corresponding responses into the mQueuedInput
list, for subsequent calls to readLine(). If the string does not match, we assert
the mismatch. If no string was expected, we assert it as an overflow.
Logs the written text if DEBUG_LOG_STREAMS is true.
if (DEBUG_LOG_STREAMS) {
Log.d(LOG_TAG, ">>> " + s);
}
SmtpSenderUnitTests.assertTrue(mOpen);
SmtpSenderUnitTests.assertTrue("Overflow writing to MockTransport", 0 != mPairs.size());
Transaction pair = mPairs.remove(0);
SmtpSenderUnitTests.assertTrue("Unexpected string written to MockTransport",
pair.mPattern != null && s.matches(pair.mPattern));
if (pair.mResponses != null) {
sendResponse(pair.mResponses);
}
|