Browse Source

Unit test beep command.

pull/134/head
Greg Holmes 9 years ago
parent
commit
1af38fc44e

+ 11
- 0
audio/src/com/dmdirc/addons/audio/AudioPluginModule.java View File

@@ -24,11 +24,22 @@ package com.dmdirc.addons.audio;
24 24
 
25 25
 import com.dmdirc.ClientModule;
26 26
 
27
+import java.awt.Toolkit;
28
+
29
+import javax.inject.Singleton;
30
+
27 31
 import dagger.Module;
32
+import dagger.Provides;
28 33
 
29 34
 /**
30 35
  * Dependency injection module for the audio plugin.
31 36
  */
32 37
 @Module(injects = {AudioCommand.class, BeepCommand.class}, addsTo = ClientModule.class)
33 38
 public class AudioPluginModule {
39
+
40
+    @Provides
41
+    @Singleton
42
+    public Toolkit getToolKit() {
43
+        return Toolkit.getDefaultToolkit();
44
+    }
34 45
 }

+ 5
- 2
audio/src/com/dmdirc/addons/audio/BeepCommand.java View File

@@ -44,21 +44,24 @@ public class BeepCommand extends Command {
44 44
     /** A command info object for this command. */
45 45
     public static final CommandInfo INFO = new BaseCommandInfo("beep",
46 46
             "beep - emits a beep", CommandType.TYPE_GLOBAL);
47
+    private final Toolkit toolkit;
47 48
 
48 49
     /**
49 50
      * Creates a new instance of this command.
50 51
      *
51 52
      * @param controller The controller to use for command information.
53
+     * @param toolkit    The toolkit used to beep
52 54
      */
53 55
     @Inject
54
-    public BeepCommand(final CommandController controller) {
56
+    public BeepCommand(final CommandController controller, final Toolkit toolkit) {
55 57
         super(controller);
58
+        this.toolkit = toolkit;
56 59
     }
57 60
 
58 61
     @Override
59 62
     public void execute(@Nonnull final FrameContainer origin,
60 63
             final CommandArguments args, final CommandContext context) {
61
-        Toolkit.getDefaultToolkit().beep();
64
+        toolkit.beep();
62 65
     }
63 66
 
64 67
 }

+ 60
- 0
audio/test/com/dmdirc/addons/audio/BeepCommandTest.java View File

@@ -0,0 +1,60 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.audio;
24
+
25
+import com.dmdirc.FrameContainer;
26
+import com.dmdirc.commandparser.CommandArguments;
27
+import com.dmdirc.commandparser.commands.context.CommandContext;
28
+import com.dmdirc.interfaces.CommandController;
29
+
30
+import java.awt.Toolkit;
31
+
32
+import org.junit.Before;
33
+import org.junit.Test;
34
+import org.junit.runner.RunWith;
35
+import org.mockito.Mock;
36
+import org.mockito.runners.MockitoJUnitRunner;
37
+
38
+import static org.mockito.Mockito.verify;
39
+
40
+@RunWith(MockitoJUnitRunner.class)
41
+public class BeepCommandTest {
42
+
43
+    @Mock private Toolkit toolkit;
44
+    @Mock private CommandController commandController;
45
+    @Mock private FrameContainer frameContainer;
46
+    @Mock private CommandArguments commandArguments;
47
+    @Mock private CommandContext commandContext;
48
+    private BeepCommand beepCommand;
49
+
50
+    @Before
51
+    public void setUp() throws Exception {
52
+        beepCommand = new BeepCommand(commandController, toolkit);
53
+    }
54
+
55
+    @Test
56
+    public void testExecute() throws Exception {
57
+        beepCommand.execute(frameContainer, commandArguments, commandContext);
58
+        verify(toolkit).beep();
59
+    }
60
+}

Loading…
Cancel
Save