01: /*
02: * Copyright (C) 2007 Rob Manning
03: * manningr@users.sourceforge.net
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19: package net.sourceforge.squirrel_sql.client.mainframe.action;
20:
21: import static org.easymock.EasyMock.isA;
22: import static org.easymock.classextension.EasyMock.createMock;
23: import static org.easymock.classextension.EasyMock.replay;
24: import static org.easymock.classextension.EasyMock.verify;
25:
26: import java.awt.Component;
27: import java.awt.Frame;
28:
29: import net.sourceforge.squirrel_sql.client.IApplication;
30: import net.sourceforge.squirrel_sql.fw.gui.IDialogUtils;
31:
32: import org.junit.After;
33: import org.junit.Before;
34: import org.junit.Test;
35:
36: public class SavePreferencesCommandTest {
37:
38: Frame mockFrame = createMock(Frame.class);
39: IApplication mockApplication = createMock(IApplication.class);
40: IDialogUtils mockDialogUtils = createMock(IDialogUtils.class);
41:
42: @Before
43: public void setUp() throws Exception {
44: }
45:
46: @After
47: public void tearDown() throws Exception {
48: }
49:
50: // Null tests
51:
52: @Test(expected=IllegalArgumentException.class)
53: public final void testSavePreferencesCommandNullApp() {
54: new SavePreferencesCommand(null, mockFrame);
55: }
56:
57: @Test(expected=IllegalArgumentException.class)
58: public final void testSavePreferencesCommandNullFrame() {
59: new SavePreferencesCommand(mockApplication, null);
60: }
61:
62: // Other tests
63:
64: @Test
65: public final void testExecute() {
66: mockApplication.saveApplicationState();
67: mockDialogUtils.showOk(isA(Component.class), isA(String.class));
68:
69: replay(mockFrame);
70: replay(mockApplication);
71: replay(mockDialogUtils);
72:
73: SavePreferencesCommand command = new SavePreferencesCommand(
74: mockApplication, mockFrame);
75: command.setDialogUtils(mockDialogUtils);
76: command.execute();
77:
78: verify(mockFrame);
79: verify(mockApplication);
80: verify(mockDialogUtils);
81:
82: }
83:
84: }
|