You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wave-commits@incubator.apache.org by wi...@apache.org on 2016/11/28 09:22:35 UTC
[2/2] incubator-wave git commit: rewritten ControllerTest to use
mockito instead of jmock
rewritten ControllerTest to use mockito instead of jmock
Project: http://git-wip-us.apache.org/repos/asf/incubator-wave/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-wave/commit/2d48da78
Tree: http://git-wip-us.apache.org/repos/asf/incubator-wave/tree/2d48da78
Diff: http://git-wip-us.apache.org/repos/asf/incubator-wave/diff/2d48da78
Branch: refs/heads/fix/dependendices-2016
Commit: 2d48da7802abc859ddbce17db7d0028cba6059f3
Parents: ad947ee
Author: wisebaldone <wi...@apache.org>
Authored: Mon Nov 28 19:22:23 2016 +1000
Committer: wisebaldone <wi...@apache.org>
Committed: Mon Nov 28 19:22:23 2016 +1000
----------------------------------------------------------------------
.../client/scheduler/knobs/ControllerTest.java | 57 ++++----------------
1 file changed, 10 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-wave/blob/2d48da78/wave/src/test/java/org/waveprotocol/wave/client/scheduler/knobs/ControllerTest.java
----------------------------------------------------------------------
diff --git a/wave/src/test/java/org/waveprotocol/wave/client/scheduler/knobs/ControllerTest.java b/wave/src/test/java/org/waveprotocol/wave/client/scheduler/knobs/ControllerTest.java
index 7cc062d..2f17a92 100644
--- a/wave/src/test/java/org/waveprotocol/wave/client/scheduler/knobs/ControllerTest.java
+++ b/wave/src/test/java/org/waveprotocol/wave/client/scheduler/knobs/ControllerTest.java
@@ -19,21 +19,21 @@
package org.waveprotocol.wave.client.scheduler.knobs;
+import junit.framework.TestCase;
import org.waveprotocol.wave.client.scheduler.Scheduler.Priority;
import org.waveprotocol.wave.client.scheduler.Scheduler.Schedulable;
-
-import org.jmock.Expectations;
-import org.jmock.integration.junit3.MockObjectTestCase;
import org.waveprotocol.wave.model.util.ReadableStringSet;
import java.util.Collection;
+import static org.mockito.Mockito.*;
+
/**
* Tests the controller components for the scheduler.
*
*/
-public class ControllerTest extends MockObjectTestCase {
+public class ControllerTest extends TestCase {
/**
* Stub implementation of a per-level UI control. Used both as a dummy and a
@@ -107,54 +107,20 @@ public class ControllerTest extends MockObjectTestCase {
knobView = mock(KnobView.class);
knobsView = mock(KnobsView.class);
stubView = new StubLevelView();
+ for (Priority p : Priority.values()) {
+ when(knobsView.create(p)).thenReturn(p.equals(Priority.MEDIUM) ? stubView : new StubLevelView());
+ }
}
- /**
- * Tells jmock to accept the things that happen to the mock level-view
- * when it gets injected into a level presenter.
- */
- private void allowKnobViewSetup() {
- /// Sigh, Jmock = tight coupling with impl details :(
- checking(new Expectations() {{
- // Stuff that happens in constructor
- one(knobView).init(with(any(KnobPresenter.class)));
- one(knobView).enable();
- one(knobView).showCount(0);
- one(knobView).hideJobs();
- }});
- }
-
- /**
- * Tells jmock to accept the things that happen to the mock knob-view
- * when it gets injected into a presenter. Also injects {@link #stubView} as
- * the per-level view of the MEDIUM priority level.
- */
- private void allowKnobsViewSetup() {
- checking(new Expectations() {{
- for (Priority p : Priority.values()) {
- one(knobsView).create(p);
- will(returnValue(p.equals(Priority.MEDIUM) ? stubView : new StubLevelView()));
- }
- }});
- }
-
- //
- // Tests below.
- //
-
public void testLevelPresenterInitialStateAndClicking() {
- allowKnobViewSetup();
KnobPresenter presenter = new KnobPresenter(knobView);
- checking(new Expectations() {{
- one(knobView).disable();
- }});
presenter.onClicked();
+ verify(knobView, times(1)).disable();
+
- checking(new Expectations() {{
- one(knobView).enable();
- }});
presenter.onClicked();
+ verify(knobView, times(2)).enable(); // is enabled by default
}
public void testLevelEnabledAndDisabled() {
@@ -167,12 +133,10 @@ public class ControllerTest extends MockObjectTestCase {
}
public void testKnobsAddLevelForEachPriority() {
- allowKnobsViewSetup();
KnobsPresenter presenter = new KnobsPresenter(knobsView);
}
public void testClickingOnLevelTogglesRunnability() {
- allowKnobsViewSetup();
KnobsPresenter presenter = new KnobsPresenter(knobsView);
assertNotNull(stubView.getListener());
@@ -184,7 +148,6 @@ public class ControllerTest extends MockObjectTestCase {
}
public void testUpdatingMediumJobCountUpdatesView() {
- allowKnobsViewSetup();
KnobsPresenter presenter = new KnobsPresenter(knobsView);
Schedulable a = new Schedulable(){};