Skip to content

Commit 3702d02

Browse files
committed
Remove build provided references and separate JUnit tests
1 parent 3fff46f commit 3702d02

File tree

7 files changed

+320
-235
lines changed

7 files changed

+320
-235
lines changed

rxjava-contrib/rxjava-swing/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ targetCompatibility = JavaVersion.VERSION_1_6
55

66
dependencies {
77
compile project(':rxjava-core')
8-
provided 'junit:junit-dep:4.10'
9-
provided 'org.mockito:mockito-core:1.8.5'
8+
testCompile 'junit:junit-dep:4.10'
9+
testCompile 'org.mockito:mockito-core:1.8.5'
1010
}
1111

1212
javadoc {

rxjava-contrib/rxjava-swing/src/main/java/rx/swing/sources/AbstractButtonSource.java

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,15 @@
1515
*/
1616
package rx.swing.sources;
1717

18-
import static org.mockito.Mockito.mock;
19-
import static org.mockito.Mockito.never;
20-
import static org.mockito.Mockito.times;
21-
import static org.mockito.Mockito.verify;
22-
2318
import java.awt.event.ActionEvent;
2419
import java.awt.event.ActionListener;
2520

2621
import javax.swing.AbstractButton;
2722

28-
import org.junit.Test;
29-
import org.mockito.Matchers;
30-
3123
import rx.Observable;
3224
import rx.Observable.OnSubscribe;
3325
import rx.Subscriber;
34-
import rx.Subscription;
3526
import rx.functions.Action0;
36-
import rx.functions.Action1;
3727
import rx.observables.SwingObservable;
3828
import rx.subscriptions.SwingSubscriptions;
3929

@@ -64,49 +54,4 @@ public void call() {
6454
});
6555
}
6656

67-
public static class UnitTest {
68-
@Test
69-
public void testObservingActionEvents() throws Throwable {
70-
SwingTestHelper.create().runInEventDispatchThread(new Action0() {
71-
72-
@Override
73-
public void call() {
74-
@SuppressWarnings("unchecked")
75-
Action1<ActionEvent> action = mock(Action1.class);
76-
@SuppressWarnings("unchecked")
77-
Action1<Throwable> error = mock(Action1.class);
78-
Action0 complete = mock(Action0.class);
79-
80-
final ActionEvent event = new ActionEvent(this, 1, "command");
81-
82-
@SuppressWarnings("serial")
83-
class TestButton extends AbstractButton {
84-
void testAction() {
85-
fireActionPerformed(event);
86-
}
87-
}
88-
89-
TestButton button = new TestButton();
90-
Subscription sub = fromActionOf(button).subscribe(action, error, complete);
91-
92-
verify(action, never()).call(Matchers.<ActionEvent> any());
93-
verify(error, never()).call(Matchers.<Throwable> any());
94-
verify(complete, never()).call();
95-
96-
button.testAction();
97-
verify(action, times(1)).call(Matchers.<ActionEvent> any());
98-
99-
button.testAction();
100-
verify(action, times(2)).call(Matchers.<ActionEvent> any());
101-
102-
sub.unsubscribe();
103-
button.testAction();
104-
verify(action, times(2)).call(Matchers.<ActionEvent> any());
105-
verify(error, never()).call(Matchers.<Throwable> any());
106-
verify(complete, never()).call();
107-
}
108-
109-
}).awaitTerminal();
110-
}
111-
}
11257
}

rxjava-contrib/rxjava-swing/src/main/java/rx/swing/sources/KeyEventSource.java

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,17 @@
1515
*/
1616
package rx.swing.sources;
1717

18-
import static java.util.Arrays.asList;
19-
import static org.mockito.Mockito.inOrder;
20-
import static org.mockito.Mockito.mock;
21-
import static org.mockito.Mockito.never;
22-
import static org.mockito.Mockito.times;
23-
import static org.mockito.Mockito.verify;
24-
2518
import java.awt.Component;
2619
import java.awt.event.KeyEvent;
2720
import java.awt.event.KeyListener;
2821
import java.util.Collections;
2922
import java.util.HashSet;
3023
import java.util.Set;
3124

32-
import javax.swing.JPanel;
33-
34-
import org.junit.Test;
35-
import org.mockito.InOrder;
36-
import org.mockito.Matchers;
37-
3825
import rx.Observable;
3926
import rx.Observable.OnSubscribe;
4027
import rx.Subscriber;
41-
import rx.Subscription;
4228
import rx.functions.Action0;
43-
import rx.functions.Action1;
4429
import rx.functions.Func1;
4530
import rx.functions.Func2;
4631
import rx.observables.SwingObservable;
@@ -117,101 +102,4 @@ public Boolean call(KeyEvent event) {
117102
return filteredKeyEvents.scan(Collections.<Integer>emptySet(), new CollectKeys());
118103
}
119104

120-
public static class UnitTest {
121-
private Component comp = new JPanel();
122-
123-
@Test
124-
public void testObservingKeyEvents() throws Throwable {
125-
SwingTestHelper.create().runInEventDispatchThread(new Action0(){
126-
127-
@Override
128-
public void call() {
129-
@SuppressWarnings("unchecked")
130-
Action1<KeyEvent> action = mock(Action1.class);
131-
@SuppressWarnings("unchecked")
132-
Action1<Throwable> error = mock(Action1.class);
133-
Action0 complete = mock(Action0.class);
134-
135-
final KeyEvent event = mock(KeyEvent.class);
136-
137-
Subscription sub = fromKeyEventsOf(comp).subscribe(action, error, complete);
138-
139-
verify(action, never()).call(Matchers.<KeyEvent> any());
140-
verify(error, never()).call(Matchers.<Throwable> any());
141-
verify(complete, never()).call();
142-
143-
fireKeyEvent(event);
144-
verify(action, times(1)).call(Matchers.<KeyEvent> any());
145-
146-
fireKeyEvent(event);
147-
verify(action, times(2)).call(Matchers.<KeyEvent> any());
148-
149-
sub.unsubscribe();
150-
fireKeyEvent(event);
151-
verify(action, times(2)).call(Matchers.<KeyEvent> any());
152-
verify(error, never()).call(Matchers.<Throwable> any());
153-
verify(complete, never()).call();
154-
}
155-
156-
}).awaitTerminal();
157-
}
158-
159-
@Test
160-
public void testObservingPressedKeys() throws Throwable {
161-
SwingTestHelper.create().runInEventDispatchThread(new Action0() {
162-
163-
@Override
164-
public void call() {
165-
@SuppressWarnings("unchecked")
166-
Action1<Set<Integer>> action = mock(Action1.class);
167-
@SuppressWarnings("unchecked")
168-
Action1<Throwable> error = mock(Action1.class);
169-
Action0 complete = mock(Action0.class);
170-
171-
Subscription sub = currentlyPressedKeysOf(comp).subscribe(action, error, complete);
172-
173-
InOrder inOrder = inOrder(action);
174-
inOrder.verify(action, times(1)).call(Collections.<Integer> emptySet());
175-
verify(error, never()).call(Matchers.<Throwable> any());
176-
verify(complete, never()).call();
177-
178-
fireKeyEvent(keyEvent(1, KeyEvent.KEY_PRESSED));
179-
inOrder.verify(action, times(1)).call(new HashSet<Integer>(asList(1)));
180-
verify(error, never()).call(Matchers.<Throwable> any());
181-
verify(complete, never()).call();
182-
183-
fireKeyEvent(keyEvent(2, KeyEvent.KEY_PRESSED));
184-
fireKeyEvent(keyEvent(KeyEvent.VK_UNDEFINED, KeyEvent.KEY_TYPED));
185-
inOrder.verify(action, times(1)).call(new HashSet<Integer>(asList(1, 2)));
186-
187-
fireKeyEvent(keyEvent(2, KeyEvent.KEY_RELEASED));
188-
inOrder.verify(action, times(1)).call(new HashSet<Integer>(asList(1)));
189-
190-
fireKeyEvent(keyEvent(3, KeyEvent.KEY_RELEASED));
191-
inOrder.verify(action, times(1)).call(new HashSet<Integer>(asList(1)));
192-
193-
fireKeyEvent(keyEvent(1, KeyEvent.KEY_RELEASED));
194-
inOrder.verify(action, times(1)).call(Collections.<Integer> emptySet());
195-
196-
sub.unsubscribe();
197-
198-
fireKeyEvent(keyEvent(1, KeyEvent.KEY_PRESSED));
199-
inOrder.verify(action, never()).call(Matchers.<Set<Integer>> any());
200-
verify(error, never()).call(Matchers.<Throwable> any());
201-
verify(complete, never()).call();
202-
}
203-
204-
}).awaitTerminal();
205-
}
206-
207-
private KeyEvent keyEvent(int keyCode, int id) {
208-
return new KeyEvent(comp, id, -1L, 0, keyCode, ' ');
209-
}
210-
211-
private void fireKeyEvent(KeyEvent event) {
212-
for (KeyListener listener: comp.getKeyListeners()) {
213-
listener.keyTyped(event);
214-
}
215-
}
216-
}
217105
}

rxjava-contrib/rxjava-swing/src/main/java/rx/swing/sources/MouseEventSource.java

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,16 @@
1515
*/
1616
package rx.swing.sources;
1717

18-
import static org.mockito.Mockito.inOrder;
19-
import static org.mockito.Mockito.mock;
20-
import static org.mockito.Mockito.never;
21-
import static org.mockito.Mockito.times;
22-
import static org.mockito.Mockito.verify;
23-
2418
import java.awt.Component;
2519
import java.awt.Point;
2620
import java.awt.event.MouseEvent;
2721
import java.awt.event.MouseListener;
2822
import java.awt.event.MouseMotionListener;
2923

30-
import javax.swing.JPanel;
31-
32-
import org.junit.Test;
33-
import org.mockito.InOrder;
34-
import org.mockito.Matchers;
35-
3624
import rx.Observable;
3725
import rx.Observable.OnSubscribe;
3826
import rx.Subscriber;
39-
import rx.Subscription;
4027
import rx.functions.Action0;
41-
import rx.functions.Action1;
4228
import rx.functions.Func2;
4329
import rx.observables.SwingObservable;
4430
import rx.subscriptions.SwingSubscriptions;
@@ -136,56 +122,4 @@ public Point call(MouseEvent ev1, MouseEvent ev2) {
136122
});
137123
}
138124

139-
public static class UnitTest {
140-
private Component comp = new JPanel();
141-
142-
@Test
143-
public void testRelativeMouseMotion() throws Throwable {
144-
SwingTestHelper.create().runInEventDispatchThread(new Action0() {
145-
146-
@Override
147-
public void call() {
148-
@SuppressWarnings("unchecked")
149-
Action1<Point> action = mock(Action1.class);
150-
@SuppressWarnings("unchecked")
151-
Action1<Throwable> error = mock(Action1.class);
152-
Action0 complete = mock(Action0.class);
153-
154-
Subscription sub = fromRelativeMouseMotion(comp).subscribe(action, error, complete);
155-
156-
InOrder inOrder = inOrder(action);
157-
158-
verify(action, never()).call(Matchers.<Point> any());
159-
verify(error, never()).call(Matchers.<Exception> any());
160-
verify(complete, never()).call();
161-
162-
fireMouseEvent(mouseEvent(0, 0));
163-
verify(action, never()).call(Matchers.<Point> any());
164-
165-
fireMouseEvent(mouseEvent(10, -5));
166-
inOrder.verify(action, times(1)).call(new Point(10, -5));
167-
168-
fireMouseEvent(mouseEvent(6, 10));
169-
inOrder.verify(action, times(1)).call(new Point(-4, 15));
170-
171-
sub.unsubscribe();
172-
fireMouseEvent(mouseEvent(0, 0));
173-
inOrder.verify(action, never()).call(Matchers.<Point> any());
174-
verify(error, never()).call(Matchers.<Exception> any());
175-
verify(complete, never()).call();
176-
}
177-
178-
}).awaitTerminal();
179-
}
180-
181-
private MouseEvent mouseEvent(int x, int y) {
182-
return new MouseEvent(comp, MouseEvent.MOUSE_MOVED, 1L, 0, x, y, 0, false);
183-
}
184-
185-
private void fireMouseEvent(MouseEvent event) {
186-
for (MouseMotionListener listener : comp.getMouseMotionListeners()) {
187-
listener.mouseMoved(event);
188-
}
189-
}
190-
}
191125
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* Copyright 2014 Netflix, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package rx.swing.sources;
17+
18+
import java.awt.event.ActionEvent;
19+
20+
import static org.mockito.Mockito.mock;
21+
import static org.mockito.Mockito.never;
22+
import static org.mockito.Mockito.times;
23+
import static org.mockito.Mockito.verify;
24+
25+
import org.junit.Test;
26+
import org.mockito.Matchers;
27+
28+
import javax.swing.AbstractButton;
29+
30+
import rx.Subscription;
31+
import rx.functions.Action0;
32+
import rx.functions.Action1;
33+
34+
public class AbstractButtonSourceTest {
35+
@Test
36+
public void testObservingActionEvents() throws Throwable {
37+
SwingTestHelper.create().runInEventDispatchThread(new Action0() {
38+
39+
@Override
40+
public void call() {
41+
@SuppressWarnings("unchecked")
42+
Action1<ActionEvent> action = mock(Action1.class);
43+
@SuppressWarnings("unchecked")
44+
Action1<Throwable> error = mock(Action1.class);
45+
Action0 complete = mock(Action0.class);
46+
47+
final ActionEvent event = new ActionEvent(this, 1, "command");
48+
49+
@SuppressWarnings("serial")
50+
class TestButton extends AbstractButton {
51+
void testAction() {
52+
fireActionPerformed(event);
53+
}
54+
}
55+
56+
TestButton button = new TestButton();
57+
Subscription sub = AbstractButtonSource.fromActionOf(button).subscribe(action,
58+
error, complete);
59+
60+
verify(action, never()).call(Matchers.<ActionEvent> any());
61+
verify(error, never()).call(Matchers.<Throwable> any());
62+
verify(complete, never()).call();
63+
64+
button.testAction();
65+
verify(action, times(1)).call(Matchers.<ActionEvent> any());
66+
67+
button.testAction();
68+
verify(action, times(2)).call(Matchers.<ActionEvent> any());
69+
70+
sub.unsubscribe();
71+
button.testAction();
72+
verify(action, times(2)).call(Matchers.<ActionEvent> any());
73+
verify(error, never()).call(Matchers.<Throwable> any());
74+
verify(complete, never()).call();
75+
}
76+
77+
}).awaitTerminal();
78+
}
79+
}

0 commit comments

Comments
 (0)