Revision: 6060
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6060&view=rev
Author: manningr
Date: 2010-12-26 22:01:14 +0000 (Sun, 26 Dec 2010)
Log Message:
-----------
Replaced the use of EasyMock with Mockito for session plugin testing as it takes less code in a test to say the same thing. Also, Mockito is more forgiving when it comes to missed expectations, so tests are a little less fragile in the face of code changes. This is done in preparation for releasing the SQuirreL plugin maven archetype.
Modified Paths:
--------------
trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/plugin/AbstractPluginTest.java
trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/plugin/AbstractSessionPluginTest.java
trunk/sql12/plugins/db2/src/test/java/net/sourceforge/squirrel_sql/plugins/db2/DB2PluginTest.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java
trunk/sql12/plugins/derby/src/test/java/net/sourceforge/squirrel_sql/plugins/derby/DerbyPluginTest.java
trunk/sql12/plugins/example/src/main/java/net/sourceforge/squirrel_sql/plugins/example/ExamplePlugin.java
trunk/sql12/plugins/example/src/main/java/net/sourceforge/squirrel_sql/plugins/example/ExampleSqlExecutionListener.java
trunk/sql12/plugins/firebird/src/test/java/net/sourceforge/squirrel_sql/plugins/firebird/FirebirdPluginTest.java
trunk/sql12/plugins/h2/src/test/java/net/sourceforge/squirrel_sql/plugins/h2/H2PluginTest.java
trunk/sql12/plugins/informix/src/test/java/net/sourceforge/squirrel_sql/plugins/informix/InformixPluginTest.java
trunk/sql12/plugins/mssql/src/test/java/net/sourceforge/squirrel_sql/plugins/mssql/MssqlPluginTest.java
trunk/sql12/plugins/mysql/src/test/java/net/sourceforge/squirrel_sql/plugins/mysql/MysqlPluginTest.java
trunk/sql12/plugins/oracle/src/test/java/net/sourceforge/squirrel_sql/plugins/oracle/OraclePluginTest.java
trunk/sql12/plugins/postgres/src/test/java/net/sourceforge/squirrel_sql/plugins/postgres/PostgresPluginTest.java
trunk/sql12/plugins/sqlparam/src/test/java/net/sourceforge/squirrel_sql/plugins/sqlparam/SQLParamPluginTest.java
Added Paths:
-----------
trunk/sql12/plugins/example/src/test/
trunk/sql12/plugins/example/src/test/java/
trunk/sql12/plugins/example/src/test/java/net/
trunk/sql12/plugins/example/src/test/java/net/sourceforge/
trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/
trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/
trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/example/
trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/example/ExamplePluginTest.java
trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/example/ExampleSqlExecutionListenerTest.java
Modified: trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/plugin/AbstractPluginTest.java
===================================================================
--- trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/plugin/AbstractPluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/plugin/AbstractPluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -18,29 +18,20 @@
*/
package net.sourceforge.squirrel_sql.client.plugin;
-import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertNotNull;
-import org.easymock.EasyMock;
-import org.junit.Assert;
import org.junit.Test;
+import org.junit.runner.RunWith;
-import utils.EasyMockHelper;
-import net.sourceforge.squirrel_sql.BaseSQuirreLJUnit4TestCase;
-import net.sourceforge.squirrel_sql.client.plugin.DefaultSessionPlugin;
-import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
-import net.sourceforge.squirrel_sql.client.session.ISession;
-import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
-
/**
* This class provides common tests for plugins. Each plugin test should simply extend this class to
* pickup the common tests.
*
*/
-public abstract class AbstractPluginTest extends BaseSQuirreLJUnit4TestCase
+@RunWith(org.mockito.runners.MockitoJUnitRunner.class)
+public abstract class AbstractPluginTest
{
protected IPlugin classUnderTest = null;
- protected EasyMockHelper mockHelper = new EasyMockHelper();
@Test
Modified: trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/plugin/AbstractSessionPluginTest.java
===================================================================
--- trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/plugin/AbstractSessionPluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/app/src/test/java/net/sourceforge/squirrel_sql/client/plugin/AbstractSessionPluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -18,43 +18,88 @@
*/
package net.sourceforge.squirrel_sql.client.plugin;
-import static org.easymock.EasyMock.expect;
+import static org.mockito.Mockito.when;
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.gui.session.SessionInternalFrame;
+import net.sourceforge.squirrel_sql.client.gui.session.SessionPanel;
+import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
+import net.sourceforge.squirrel_sql.client.session.IObjectTreeAPI;
+import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
import net.sourceforge.squirrel_sql.client.session.ISession;
import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
+import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
-public abstract class AbstractSessionPluginTest extends AbstractPluginTest implements DatabaseProductVersionData
+public abstract class AbstractSessionPluginTest extends AbstractPluginTest implements
+ DatabaseProductVersionData
{
+ @Mock
+ protected ISession mockSession;
+
+ @Mock
+ protected ISQLDatabaseMetaData mockSQLDatabaseMetaData;
+
+ @Mock
+ protected IApplication mockApplication;
+
+ @Mock
+ protected IMessageHandler mockMessageHandler;
+ @Mock
+ protected SessionInternalFrame mockSessionInternalFrame;
+
+ @Mock
+ protected SquirrelPreferences mockSquirrelPreferences;
+
+ @Mock
+ protected IObjectTreeAPI mockObjectTreeAPI;
+
+ @Mock
+ protected SessionPanel mockSessionPanel;
+
+ @Mock
+ protected ISQLPanelAPI mockPanelAPI;
+
+
+ @Before
+ public void setUp() throws Exception {
+ when(mockApplication.getMessageHandler()).thenReturn(mockMessageHandler);
+ when(mockApplication.getSquirrelPreferences()).thenReturn(mockSquirrelPreferences);
+ when(mockSession.getApplication()).thenReturn(mockApplication);
+ when(mockSession.getMetaData()).thenReturn(mockSQLDatabaseMetaData);
+ when(mockSession.getSessionInternalFrame()).thenReturn(mockSessionInternalFrame);
+ when(mockSession.getSessionSheet()).thenReturn(mockSessionPanel);
+ when(mockSQLDatabaseMetaData.getDatabaseProductName()).thenReturn(getDatabaseProductName());
+ when(mockSQLDatabaseMetaData.getDatabaseProductVersion()).thenReturn(getDatabaseProductVersion());
+ when(mockSessionInternalFrame.getObjectTreeAPI()).thenReturn(mockObjectTreeAPI);
+ when(mockSessionPanel.getSQLPaneAPI()).thenReturn(mockPanelAPI);
+ }
+
@Test
- public void testIsPluginSession() throws Exception {
- ISession mockSession = mockHelper.createMock(ISession.class);
- ISQLDatabaseMetaData mockSQLDatabaseMetaData = mockHelper.createMock(ISQLDatabaseMetaData.class);
- expect(mockSession.getMetaData()).andStubReturn(mockSQLDatabaseMetaData);
- expect(mockSQLDatabaseMetaData.getDatabaseProductName()).andStubReturn(getDatabaseProductName());
- expect(mockSQLDatabaseMetaData.getDatabaseProductVersion()).andStubReturn(getDatabaseProductVersion());
-
- mockHelper.replayAll();
- if (classUnderTest instanceof DefaultSessionPlugin) {
- DefaultSessionPlugin plugin = (DefaultSessionPlugin)classUnderTest;
+ public void testIsPluginSession() throws Exception
+ {
+ if (classUnderTest instanceof DefaultSessionPlugin)
+ {
+ DefaultSessionPlugin plugin = (DefaultSessionPlugin) classUnderTest;
Assert.assertTrue(plugin.isPluginSession(mockSession));
}
- mockHelper.verifyAll();
}
-
+
/**
* Subclass tests should provide a database product name for a session that corresponds to the plugin being
- * tested by overriding this method
+ * tested by overriding this method
*/
protected abstract String getDatabaseProductName();
/**
- * Subclass tests should provide a database product version for a session that corresponds to the plugin being
- * tested by overriding this method
- */
+ * Subclass tests should provide a database product version for a session that corresponds to the plugin
+ * being tested by overriding this method
+ */
protected abstract String getDatabaseProductVersion();
-
+
}
Modified: trunk/sql12/plugins/db2/src/test/java/net/sourceforge/squirrel_sql/plugins/db2/DB2PluginTest.java
===================================================================
--- trunk/sql12/plugins/db2/src/test/java/net/sourceforge/squirrel_sql/plugins/db2/DB2PluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/db2/src/test/java/net/sourceforge/squirrel_sql/plugins/db2/DB2PluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -30,6 +30,7 @@
@Before
public void setUp() throws Exception
{
+ super.setUp();
classUnderTest = new DB2Plugin();
}
Modified: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -172,8 +172,12 @@
IApplication app = getApplication();
ActionCollection coll = app.getActionCollection();
+
+ PasteTableAction pasteTableAction = new PasteTableAction(app, _resources, this);
+ pasteTableAction.setDbCopyPreferenceBean(PreferencesManager.getPreferences());
+
coll.add(new CopyTableAction(app, _resources, this));
- coll.add(new PasteTableAction(app, _resources, this));
+ coll.add(pasteTableAction);
setPasteMenuEnabled(false);
}
Modified: trunk/sql12/plugins/derby/src/test/java/net/sourceforge/squirrel_sql/plugins/derby/DerbyPluginTest.java
===================================================================
--- trunk/sql12/plugins/derby/src/test/java/net/sourceforge/squirrel_sql/plugins/derby/DerbyPluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/derby/src/test/java/net/sourceforge/squirrel_sql/plugins/derby/DerbyPluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -29,6 +29,7 @@
@Before
public void setUp() throws Exception
{
+ super.setUp();
classUnderTest = new DerbyPlugin();
}
Modified: trunk/sql12/plugins/example/src/main/java/net/sourceforge/squirrel_sql/plugins/example/ExamplePlugin.java
===================================================================
--- trunk/sql12/plugins/example/src/main/java/net/sourceforge/squirrel_sql/plugins/example/ExamplePlugin.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/example/src/main/java/net/sourceforge/squirrel_sql/plugins/example/ExamplePlugin.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -13,16 +13,19 @@
import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
/**
- * The Example plugin class. This plugin does the following: 1. If the database types is DB2, it registers a
- * menu action in the popup menu for view and procedure nodes in the ObjectTree. For detailed information and
- * usage of the Plugin API see the following:
+ * <pre>
+ * The Example plugin class. If the database session's type is DB2, this plugin registers a menu action in
+ * the popup menu for view and procedure nodes in the ObjectTree.
+ *
+ * For detailed information and usage of the Plugin API see the following:
+ *
* https://sourceforge.net/apps/trac/squirrel-sql/wiki/SQuirreLSQLClientPluginAPI
+ * </pre>
*/
public class ExamplePlugin extends DefaultSessionPlugin
{
private PluginResources _resources;
-
/**
* Return the internal name of this plugin.
*
@@ -127,20 +130,20 @@
*
* @param session
* The session that is starting.
- * @return An implementation of PluginSessionCallback or null to indicate the plugin does not work with this
- * session
+ * @return An implementation of PluginSessionCallback or null to indicate the plugin does not work with
+ * this session
*/
public PluginSessionCallback sessionStarted(ISession session)
{
// Adds the view and procedure script actions if the session is DB2.
addTreeNodeMenuActionsForDB2(session);
-
+
// Register a custom ISQLExecutionListener implementation that simply prints all SQL being executed to
// the message panel.
IMessageHandler messageHandler = session.getApplication().getMessageHandler();
ExampleSqlExecutionListener sqlExecutionListener = new ExampleSqlExecutionListener(messageHandler);
session.getSessionSheet().getSQLPaneAPI().addSQLExecutionListener(sqlExecutionListener);
-
+
return new PluginSessionCallbackAdaptor(this);
}
@@ -155,10 +158,10 @@
// Add context menu items to the object tree's view and procedure nodes.
IObjectTreeAPI otApi = session.getSessionInternalFrame().getObjectTreeAPI();
- otApi.addToPopup(DatabaseObjectType.VIEW, new ScriptDB2ViewAction(getApplication(), _resources,
- session));
- otApi.addToPopup(DatabaseObjectType.PROCEDURE, new ScriptDB2ProcedureAction(getApplication(),
+ otApi.addToPopup(DatabaseObjectType.VIEW, new ScriptDB2ViewAction(session.getApplication(),
_resources, session));
+ otApi.addToPopup(DatabaseObjectType.PROCEDURE, new ScriptDB2ProcedureAction(
+ session.getApplication(), _resources, session));
}
}
catch (Exception e)
Modified: trunk/sql12/plugins/example/src/main/java/net/sourceforge/squirrel_sql/plugins/example/ExampleSqlExecutionListener.java
===================================================================
--- trunk/sql12/plugins/example/src/main/java/net/sourceforge/squirrel_sql/plugins/example/ExampleSqlExecutionListener.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/example/src/main/java/net/sourceforge/squirrel_sql/plugins/example/ExampleSqlExecutionListener.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -28,6 +28,7 @@
*/
public class ExampleSqlExecutionListener implements ISQLExecutionListener
{
+ /** This is what gives the ability to print a message to the message panel */
private final IMessageHandler _messageHandler;
public ExampleSqlExecutionListener(IMessageHandler messageHandler) {
@@ -45,7 +46,8 @@
{
_messageHandler.showMessage("statementExecuting: "+sql);
- // We don't modify the SQL in this example. We could veto it's execution be returned null.
+ // We don't modify the SQL in this example. in addition to modifying it, we could veto it's execution
+ // by returning null.
return sql;
}
Added: trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/example/ExamplePluginTest.java
===================================================================
--- trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/example/ExamplePluginTest.java (rev 0)
+++ trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/example/ExamplePluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -0,0 +1,99 @@
+package net.sourceforge.squirrel_sql.plugins.example;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+import net.sourceforge.squirrel_sql.client.plugin.AbstractSessionPluginTest;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * This test extends AbstractSessionPluginTest which provides testing for many of the methods in the
+ * ISessionPlugin interface that are implemented by such a plugin. Run this test through a code coverage tool
+ * such as Emma and you will find that many of the simpler methods in the interface are covered.
+ */
+public class ExamplePluginTest extends AbstractSessionPluginTest
+{
+
+ /**
+ * getDatabaseProductName returns "DB2" because that is the product name for sessions that the example
+ * plugin is interested in. This value will be returned by the SQLDatabaseMetaData for the method called
+ * getDatabaseProductName() that is associated with Session that is used when testing methods that on the
+ * ISessionPlugin interface that require a Session.
+ *
+ * @see net.sourceforge.squirrel_sql.client.plugin.AbstractSessionPluginTest#getDatabaseProductName()
+ */
+ @Override
+ protected String getDatabaseProductName()
+ {
+ return "DB2";
+ }
+
+ /**
+ * No version is given here, because it is not required to distinguish dialects, since there is only one
+ * DB2 dialect at the current time.
+ *
+ * @see net.sourceforge.squirrel_sql.client.plugin.AbstractSessionPluginTest#getDatabaseProductVersion()
+ */
+ @Override
+ protected String getDatabaseProductVersion()
+ {
+ return null;
+ }
+
+ @Before
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ classUnderTest = new ExamplePlugin();
+ }
+
+ @Test
+ public void testSessionStarted() throws Exception
+ {
+ classUnderTest.initialize();
+ ((ExamplePlugin) classUnderTest).sessionStarted(mockSession);
+ }
+
+ @Test
+ public void testSessionStartedNullApplication() throws Exception
+ {
+ try
+ {
+ when(mockSession.getApplication()).thenReturn(null);
+ classUnderTest.initialize();
+ ((ExamplePlugin) classUnderTest).sessionStarted(mockSession);
+ fail("Exception to get an exception for null IApplication returned from Session.getApplication");
+ }
+ catch (Exception e)
+ {
+ // This is expected.
+ }
+ }
+
+ @Test
+ public void testGetGlobalPreferencePanels() {
+ assertNotNull(classUnderTest.getGlobalPreferencePanels());
+ }
+
+}
Added: trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/example/ExampleSqlExecutionListenerTest.java
===================================================================
--- trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/example/ExampleSqlExecutionListenerTest.java (rev 0)
+++ trunk/sql12/plugins/example/src/test/java/net/sourceforge/squirrel_sql/plugins/example/ExampleSqlExecutionListenerTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -0,0 +1,78 @@
+package net.sourceforge.squirrel_sql.plugins.example;
+
+import static org.junit.Assert.*;
+
+import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+
+/*
+ * Copyright (C) 2010 Rob Manning
+ * man...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * A simple test that uses Mockito to create a mock (IMessageHandler) that is required to construct the
+ * class that is being tested (ExampleSqlExecutionListener).
+ */
+@RunWith(org.mockito.runners.MockitoJUnitRunner.class)
+public class ExampleSqlExecutionListenerTest
+{
+
+ /**
+ * Class that is being tested. This should always be called classUnderTest to distinguish it as the
+ * thing being tested.
+ */
+ private ExampleSqlExecutionListener classUnderTest = null;
+
+ /**
+ * The @Mock annotation in conjunction with the MockitoJUnitRunner is pure magic. This creates the mock
+ * automatically and injects it into this test class. To the naked eye, mockMessageHandler appears to be
+ * uninitialized here. However, because it's annotated with @Mock, it actually is set to a Mockito
+ * mock implementation of IMessageHandler.
+ */
+ @Mock
+ private IMessageHandler mockMessageHandler;
+
+ @Before
+ public void setUp() {
+ classUnderTest = new ExampleSqlExecutionListener(mockMessageHandler);
+ }
+
+ @Test
+ public void testStatementExecuted()
+ {
+ final String sqlToTest = "select * from testtable";
+ classUnderTest.statementExecuted(sqlToTest);
+
+ // We just want to verify that the message handler's showMessage method was called.
+ Mockito.verify(mockMessageHandler).showMessage("statementExecuted: "+sqlToTest);
+ }
+
+ @Test
+ public void testStatementExecuting()
+ {
+ final String sqlToTest = "select * from testtable";
+ String result = classUnderTest.statementExecuting(sqlToTest);
+ assertEquals(sqlToTest, result);
+ }
+
+}
Modified: trunk/sql12/plugins/firebird/src/test/java/net/sourceforge/squirrel_sql/plugins/firebird/FirebirdPluginTest.java
===================================================================
--- trunk/sql12/plugins/firebird/src/test/java/net/sourceforge/squirrel_sql/plugins/firebird/FirebirdPluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/firebird/src/test/java/net/sourceforge/squirrel_sql/plugins/firebird/FirebirdPluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -30,6 +30,7 @@
@Before
public void setUp() throws Exception
{
+ super.setUp();
classUnderTest = new FirebirdPlugin();
}
Modified: trunk/sql12/plugins/h2/src/test/java/net/sourceforge/squirrel_sql/plugins/h2/H2PluginTest.java
===================================================================
--- trunk/sql12/plugins/h2/src/test/java/net/sourceforge/squirrel_sql/plugins/h2/H2PluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/h2/src/test/java/net/sourceforge/squirrel_sql/plugins/h2/H2PluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -29,6 +29,7 @@
@Before
public void setUp() throws Exception
{
+ super.setUp();
classUnderTest = new H2Plugin();
}
Modified: trunk/sql12/plugins/informix/src/test/java/net/sourceforge/squirrel_sql/plugins/informix/InformixPluginTest.java
===================================================================
--- trunk/sql12/plugins/informix/src/test/java/net/sourceforge/squirrel_sql/plugins/informix/InformixPluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/informix/src/test/java/net/sourceforge/squirrel_sql/plugins/informix/InformixPluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -29,6 +29,7 @@
@Before
public void setUp() throws Exception
{
+ super.setUp();
classUnderTest = new InformixPlugin();
}
Modified: trunk/sql12/plugins/mssql/src/test/java/net/sourceforge/squirrel_sql/plugins/mssql/MssqlPluginTest.java
===================================================================
--- trunk/sql12/plugins/mssql/src/test/java/net/sourceforge/squirrel_sql/plugins/mssql/MssqlPluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/mssql/src/test/java/net/sourceforge/squirrel_sql/plugins/mssql/MssqlPluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -29,6 +29,7 @@
@Before
public void setUp() throws Exception
{
+ super.setUp();
classUnderTest = new MssqlPlugin();
}
Modified: trunk/sql12/plugins/mysql/src/test/java/net/sourceforge/squirrel_sql/plugins/mysql/MysqlPluginTest.java
===================================================================
--- trunk/sql12/plugins/mysql/src/test/java/net/sourceforge/squirrel_sql/plugins/mysql/MysqlPluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/mysql/src/test/java/net/sourceforge/squirrel_sql/plugins/mysql/MysqlPluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -18,11 +18,9 @@
*/
package net.sourceforge.squirrel_sql.plugins.mysql;
-import static org.easymock.EasyMock.expect;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
import net.sourceforge.squirrel_sql.client.plugin.AbstractSessionPluginTest;
-import net.sourceforge.squirrel_sql.client.session.ISession;
-import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
import org.junit.After;
import org.junit.Before;
@@ -31,16 +29,11 @@
public class MysqlPluginTest extends AbstractSessionPluginTest
{
- // Common mocks
- private ISQLDatabaseMetaData mockMetaData = mockHelper.createMock(ISQLDatabaseMetaData.class);
- private ISession mockSession = mockHelper.createMock(ISession.class);
-
-
@Before
public void setUp() throws Exception
{
- expect(mockSession.getMetaData()).andStubReturn(mockMetaData);
+ super.setUp();
classUnderTest = new MysqlPlugin();
}
@@ -72,17 +65,14 @@
private void testIsPluginSession(String productName, String productVersion, boolean isPluginSession)
throws Exception
{
- expect(mockMetaData.getDatabaseProductName()).andReturn(productName).anyTimes();
- expect(mockMetaData.getDatabaseProductVersion()).andReturn(productVersion).anyTimes();
-
- mockHelper.replayAll();
-
+ when(super.mockSQLDatabaseMetaData.getDatabaseProductName()).thenReturn(productName);
+ when(super.mockSQLDatabaseMetaData.getDatabaseProductVersion()).thenReturn(productVersion);
+
boolean result = ((MysqlPlugin)classUnderTest).isPluginSession(mockSession);
assertEquals("isPluginSession() != expected value: ",
isPluginSession, result);
- mockHelper.verifyAll();
}
@Override
Modified: trunk/sql12/plugins/oracle/src/test/java/net/sourceforge/squirrel_sql/plugins/oracle/OraclePluginTest.java
===================================================================
--- trunk/sql12/plugins/oracle/src/test/java/net/sourceforge/squirrel_sql/plugins/oracle/OraclePluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/oracle/src/test/java/net/sourceforge/squirrel_sql/plugins/oracle/OraclePluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -64,6 +64,7 @@
@Before
public void setUp() throws Exception
{
+ super.setUp();
pluginUnderTest = new OraclePlugin();
md = FwTestUtil.getEasyMockSQLMetaData("oracle", "jdbc:oracle:thin:@host:1521:sid", false, false);
String[] functions = new String[] { OracleExceptionFormatter.OFFSET_FUNCTION_NAME };
Modified: trunk/sql12/plugins/postgres/src/test/java/net/sourceforge/squirrel_sql/plugins/postgres/PostgresPluginTest.java
===================================================================
--- trunk/sql12/plugins/postgres/src/test/java/net/sourceforge/squirrel_sql/plugins/postgres/PostgresPluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/postgres/src/test/java/net/sourceforge/squirrel_sql/plugins/postgres/PostgresPluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -29,6 +29,7 @@
@Before
public void setUp() throws Exception
{
+ super.setUp();
classUnderTest = new PostgresPlugin();
}
Modified: trunk/sql12/plugins/sqlparam/src/test/java/net/sourceforge/squirrel_sql/plugins/sqlparam/SQLParamPluginTest.java
===================================================================
--- trunk/sql12/plugins/sqlparam/src/test/java/net/sourceforge/squirrel_sql/plugins/sqlparam/SQLParamPluginTest.java 2010-12-26 21:56:42 UTC (rev 6059)
+++ trunk/sql12/plugins/sqlparam/src/test/java/net/sourceforge/squirrel_sql/plugins/sqlparam/SQLParamPluginTest.java 2010-12-26 22:01:14 UTC (rev 6060)
@@ -18,28 +18,21 @@
*/
package net.sourceforge.squirrel_sql.plugins.sqlparam;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.expectLastCall;
-import static org.easymock.EasyMock.isA;
-import net.sourceforge.squirrel_sql.client.gui.session.SessionPanel;
-import net.sourceforge.squirrel_sql.client.plugin.AbstractPluginTest;
+import net.sourceforge.squirrel_sql.client.plugin.AbstractSessionPluginTest;
import net.sourceforge.squirrel_sql.client.plugin.DatabaseProductVersionData;
import net.sourceforge.squirrel_sql.client.plugin.ISessionPlugin;
-import net.sourceforge.squirrel_sql.client.session.ISQLPanelAPI;
-import net.sourceforge.squirrel_sql.client.session.ISession;
-import net.sourceforge.squirrel_sql.client.session.event.ISQLExecutionListener;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-public class SQLParamPluginTest extends AbstractPluginTest implements DatabaseProductVersionData
+public class SQLParamPluginTest extends AbstractSessionPluginTest implements DatabaseProductVersionData
{
@Before
public void setUp() throws Exception
{
+ super.setUp();
classUnderTest = new SQLParamPlugin();
}
@@ -56,21 +49,6 @@
// close events on shutdown.
@Test
public void testMultipleSessionEndings() {
-
- ISession mockSession = mockHelper.createMock("mockSession", ISession.class);
- SessionPanel mockSessionPanel = mockHelper.createMock("mockSessionPanel", SessionPanel.class);
- ISQLPanelAPI mockSQLPanelAPI = mockHelper.createMock("mockSQLPanelAPI", ISQLPanelAPI.class);
- EasyMock.makeThreadSafe(mockSQLPanelAPI, true);
-
- expect(mockSession.getSessionSheet()).andStubReturn(mockSessionPanel);
- expect(mockSessionPanel.getSQLPaneAPI()).andStubReturn(mockSQLPanelAPI);
- mockSQLPanelAPI.addSQLExecutionListener(isA(ISQLExecutionListener.class));
- expectLastCall().anyTimes();
- mockSQLPanelAPI.removeSQLExecutionListener(isA(ISQLExecutionListener.class));
- expectLastCall().anyTimes();
-
- mockHelper.replayAll();
-
((ISessionPlugin)classUnderTest).sessionCreated(mockSession);
((ISessionPlugin)classUnderTest).sessionStarted(mockSession);
// Give the AWT thread time to finish processing the event.
@@ -78,9 +56,28 @@
((ISessionPlugin)classUnderTest).sessionEnding(mockSession);
((ISessionPlugin)classUnderTest).sessionEnding(mockSession);
+ }
-
- mockHelper.verifyAll();
+ /**
+ * @see net.sourceforge.squirrel_sql.client.plugin.AbstractSessionPluginTest#getDatabaseProductName()
+ */
+ @Override
+ protected String getDatabaseProductName()
+ {
+ // This plugin is not really database-specific. SQL execution listener API is tied to sessions, so this
+ // plugin needs to be notified when they are started.
+ return null;
}
+
+ /**
+ * @see net.sourceforge.squirrel_sql.client.plugin.AbstractSessionPluginTest#getDatabaseProductVersion()
+ */
+ @Override
+ protected String getDatabaseProductVersion()
+ {
+ // This plugin is not really database-specific. SQL execution listener API is tied to sessions, so this
+ // plugin needs to be notified when they are started.
+ return null;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|