Commit 0fa945a7 authored by Daryl's avatar Daryl

Updated gmail plugin and unit test, removed unused class.

parent 59dc065c
......@@ -18,6 +18,7 @@ public interface SimplexTransportReader {
* argument indicates whether the reader is being closed because of an
* exception and the second argument indicates whether the connection was
* recognised, which may affect how resources are disposed of.
* @throws IOException
*/
void dispose(boolean exception, boolean recognised);
void dispose(boolean exception, boolean recognised) throws IOException;
}
......@@ -25,6 +25,7 @@ public interface SimplexTransportWriter {
* Closes the writer and disposes of any associated resources. The
* argument indicates whether the writer is being closed because of an
* exception, which may affect how resources are disposed of.
* @throws IOException
*/
void dispose(boolean exception);
void dispose(boolean exception) throws IOException;
}
package net.sf.briar.plugins.email;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.microedition.io.StreamConnection;
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
public class GmailTransportConnectionReader implements SimplexTransportReader{
private static final Logger LOG = Logger.getLogger(GmailTransportConnectionReader.class.getName());
private final StreamConnection stream;
GmailTransportConnectionReader(StreamConnection stream) {
this.stream = stream;
}
public InputStream getInputStream() throws IOException {
return stream.openInputStream();
}
public void dispose(boolean exception, boolean recognised) {
try {
stream.close();
} catch(IOException e) {
if(LOG.isLoggable(Level.WARNING)) LOG.warning(e.toString());
}
}
}
package net.sf.briar.plugins.email;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.Executors;
import net.sf.briar.BriarTestCase;
import net.sf.briar.api.ContactId;
import net.sf.briar.api.TransportConfig;
import net.sf.briar.api.TransportProperties;
......@@ -15,6 +19,7 @@ import net.sf.briar.api.plugins.simplex.SimplexPluginCallback;
import net.sf.briar.api.plugins.simplex.SimplexTransportReader;
import net.sf.briar.api.plugins.simplex.SimplexTransportWriter;
import org.jmock.Mockery;
import org.junit.Before;
import org.junit.Test;
......@@ -23,104 +28,100 @@ import org.junit.Test;
* and CONTACT1_EMAIL - (as recipient email address)
*/
public class GmailPluginTester {
public class GmailPluginTest {
SimplexPluginCallback callback;
TransportProperties local, props1;
TransportConfig config;
ContactId test1;
Map<ContactId, TransportProperties> map = new HashMap<ContactId, TransportProperties>();
SimplexPluginCallback callback;
TransportProperties local, props1;
TransportConfig config;
ContactId test1;
Map<ContactId,TransportProperties> map = new HashMap<ContactId, TransportProperties>();
@Before
public void setup()
{
public void setup() {
local = new TransportProperties();
local.put("email",System.getenv("USER_GMAIL_ADDRESS"));
local.put("email", System.getenv("USER_GMAIL_ADDRESS"));
config = new TransportConfig();
config.put("username", System.getenv("GMAIL_USERNAME"));
config.put("password", System.getenv("GMAIL_PASSWORD"));
props1 = new TransportProperties();
props1.put("email", System.getenv("CONTACT1_EMAIL"));
test1 = new ContactId(12);
map.put(test1, props1);
assertEquals(1,map.size());
assertEquals(1, map.size());
callback = new SimplexPluginCallback() {
public void showMessage(String... message) {
}
public void showMessage(String... message) {}
public boolean showConfirmationMessage(String... message) {
return false;
}
public int showChoice(String[] options, String... message) {
return 0;
}
public void setLocalProperties(TransportProperties p) {
local = p;
}
public void setConfig(TransportConfig c) {
config = c;
}
public Map<ContactId, TransportProperties> getRemoteProperties() {
return map;
}
public TransportProperties getLocalProperties() {
return local;
}
public TransportConfig getConfig() {
return config;
}
public void writerCreated(ContactId c, SimplexTransportWriter w) {}
public void readerCreated(SimplexTransportReader r) {}
};
callback.setLocalProperties(local);
callback.setLocalProperties(local);
callback.setConfig(config);
}
@Test
public void testGetID()
{
GmailPlugin pluginTest = new GmailPlugin(Executors.newSingleThreadExecutor(), callback);
assertArrayEquals(GmailPlugin.TRANSPORT_ID,pluginTest.getId().getBytes());
}
@Test
public void testPluginFactoryCreation()
{
GmailPluginFactory plugin = new GmailPluginFactory();
plugin.createPlugin(Executors.newSingleThreadExecutor(), callback);
public void testGetID() throws IOException {
GmailPlugin pluginTest = new GmailPlugin(
Executors.newSingleThreadExecutor(), callback);
assertArrayEquals(GmailPlugin.TRANSPORT_ID, pluginTest.getId()
.getBytes());
}
@Test
public void testGmailPluginIMAP()
{
GmailPlugin pluginTest = new GmailPlugin(Executors.newSingleThreadExecutor(), callback);
public void testGmailPluginIMAP() throws IOException {
GmailPlugin pluginTest = new GmailPlugin(
Executors.newSingleThreadExecutor(), callback);
try {
pluginTest.start();
} catch (IOException e) {
System.out.println("IO Exception got caught");
fail();
}
finally{
pluginTest.stop();
}
}
@Test
public void testGmailSMTP()
{
GmailPlugin pluginTest = new GmailPlugin(Executors.newSingleThreadExecutor(), callback);
public void testGmailSMTP() throws IOException {
GmailPlugin pluginTest = new GmailPlugin(
Executors.newSingleThreadExecutor(), callback);
assertEquals(true, pluginTest.connectSMTP(test1));
assertEquals(false, pluginTest.connectSMTP(new ContactId(7)));
pluginTest.stop();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment