Skip to content

Commit cc7958d

Browse files
author
Pedro Viegas
committed
moving tests to test source folder #439
1 parent 1c66113 commit cc7958d

File tree

140 files changed

+11833
-12067
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+11833
-12067
lines changed

rxjava-core/src/main/java/rx/Scheduler.java

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,17 @@
1515
*/
1616
package rx;
1717

18-
import static org.mockito.Matchers.*;
19-
import static org.mockito.Mockito.*;
20-
21-
import java.util.Date;
22-
import java.util.concurrent.TimeUnit;
23-
import java.util.concurrent.atomic.AtomicBoolean;
24-
25-
import org.junit.Test;
26-
import org.mockito.InOrder;
27-
import org.mockito.Mockito;
28-
29-
import rx.concurrency.TestScheduler;
3018
import rx.subscriptions.CompositeSubscription;
3119
import rx.subscriptions.MultipleAssignmentSubscription;
3220
import rx.subscriptions.Subscriptions;
3321
import rx.util.functions.Action0;
3422
import rx.util.functions.Action1;
35-
import rx.util.functions.Func1;
3623
import rx.util.functions.Func2;
3724

25+
import java.util.Date;
26+
import java.util.concurrent.TimeUnit;
27+
import java.util.concurrent.atomic.AtomicBoolean;
28+
3829
/**
3930
* Represents an object that schedules units of work.
4031
* <p>
@@ -264,46 +255,4 @@ public long now() {
264255
public int degreeOfParallelism() {
265256
return Runtime.getRuntime().availableProcessors();
266257
}
267-
268-
public static class UnitTest {
269-
@SuppressWarnings("unchecked")
270-
// mocking is unchecked, unfortunately
271-
@Test
272-
public void testPeriodicScheduling() {
273-
final Func1<Long, Void> calledOp = mock(Func1.class);
274-
275-
final TestScheduler scheduler = new TestScheduler();
276-
Subscription subscription = scheduler.schedulePeriodically(new Action0() {
277-
@Override
278-
public void call() {
279-
System.out.println(scheduler.now());
280-
calledOp.call(scheduler.now());
281-
}
282-
}, 1, 2, TimeUnit.SECONDS);
283-
284-
verify(calledOp, never()).call(anyLong());
285-
286-
InOrder inOrder = Mockito.inOrder(calledOp);
287-
288-
scheduler.advanceTimeBy(999L, TimeUnit.MILLISECONDS);
289-
inOrder.verify(calledOp, never()).call(anyLong());
290-
291-
scheduler.advanceTimeBy(1L, TimeUnit.MILLISECONDS);
292-
inOrder.verify(calledOp, times(1)).call(1000L);
293-
294-
scheduler.advanceTimeBy(1999L, TimeUnit.MILLISECONDS);
295-
inOrder.verify(calledOp, never()).call(3000L);
296-
297-
scheduler.advanceTimeBy(1L, TimeUnit.MILLISECONDS);
298-
inOrder.verify(calledOp, times(1)).call(3000L);
299-
300-
scheduler.advanceTimeBy(5L, TimeUnit.SECONDS);
301-
inOrder.verify(calledOp, times(1)).call(5000L);
302-
inOrder.verify(calledOp, times(1)).call(7000L);
303-
304-
subscription.unsubscribe();
305-
scheduler.advanceTimeBy(11L, TimeUnit.SECONDS);
306-
inOrder.verify(calledOp, never()).call(anyLong());
307-
}
308-
}
309258
}

rxjava-core/src/main/java/rx/concurrency/CurrentThreadScheduler.java

Lines changed: 4 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,14 @@
1515
*/
1616
package rx.concurrency;
1717

18-
import static org.mockito.Mockito.*;
18+
import rx.Scheduler;
19+
import rx.Subscription;
20+
import rx.util.functions.Func2;
1921

2022
import java.util.PriorityQueue;
2123
import java.util.concurrent.TimeUnit;
2224
import java.util.concurrent.atomic.AtomicInteger;
2325

24-
import org.junit.Test;
25-
import org.mockito.InOrder;
26-
27-
import rx.Scheduler;
28-
import rx.Subscription;
29-
import rx.util.functions.Action0;
30-
import rx.util.functions.Func2;
31-
3226
/**
3327
* Schedules work on the current thread but does not execute immediately. Work is put in a queue and executed after the current unit of work is completed.
3428
*/
@@ -41,7 +35,7 @@ public static CurrentThreadScheduler getInstance() {
4135

4236
private static final ThreadLocal<PriorityQueue<TimedAction>> QUEUE = new ThreadLocal<PriorityQueue<TimedAction>>();
4337

44-
private CurrentThreadScheduler() {
38+
CurrentThreadScheduler() {
4539
}
4640

4741
private final AtomicInteger counter = new AtomicInteger(0);
@@ -102,126 +96,4 @@ public int compareTo(TimedAction that) {
10296
return result;
10397
}
10498
}
105-
106-
public static class UnitTest {
107-
108-
@Test
109-
public void testNestedActions() {
110-
final CurrentThreadScheduler scheduler = new CurrentThreadScheduler();
111-
112-
final Action0 firstStepStart = mock(Action0.class);
113-
final Action0 firstStepEnd = mock(Action0.class);
114-
115-
final Action0 secondStepStart = mock(Action0.class);
116-
final Action0 secondStepEnd = mock(Action0.class);
117-
118-
final Action0 thirdStepStart = mock(Action0.class);
119-
final Action0 thirdStepEnd = mock(Action0.class);
120-
121-
final Action0 firstAction = new Action0() {
122-
@Override
123-
public void call() {
124-
firstStepStart.call();
125-
firstStepEnd.call();
126-
}
127-
};
128-
final Action0 secondAction = new Action0() {
129-
@Override
130-
public void call() {
131-
secondStepStart.call();
132-
scheduler.schedule(firstAction);
133-
secondStepEnd.call();
134-
135-
}
136-
};
137-
final Action0 thirdAction = new Action0() {
138-
@Override
139-
public void call() {
140-
thirdStepStart.call();
141-
scheduler.schedule(secondAction);
142-
thirdStepEnd.call();
143-
}
144-
};
145-
146-
InOrder inOrder = inOrder(firstStepStart, firstStepEnd, secondStepStart, secondStepEnd, thirdStepStart, thirdStepEnd);
147-
148-
scheduler.schedule(thirdAction);
149-
150-
inOrder.verify(thirdStepStart, times(1)).call();
151-
inOrder.verify(thirdStepEnd, times(1)).call();
152-
inOrder.verify(secondStepStart, times(1)).call();
153-
inOrder.verify(secondStepEnd, times(1)).call();
154-
inOrder.verify(firstStepStart, times(1)).call();
155-
inOrder.verify(firstStepEnd, times(1)).call();
156-
}
157-
158-
@Test
159-
public void testSequenceOfActions() {
160-
final CurrentThreadScheduler scheduler = new CurrentThreadScheduler();
161-
162-
final Action0 first = mock(Action0.class);
163-
final Action0 second = mock(Action0.class);
164-
165-
scheduler.schedule(first);
166-
scheduler.schedule(second);
167-
168-
verify(first, times(1)).call();
169-
verify(second, times(1)).call();
170-
171-
}
172-
173-
@Test
174-
public void testSequenceOfDelayedActions() {
175-
final CurrentThreadScheduler scheduler = new CurrentThreadScheduler();
176-
177-
final Action0 first = mock(Action0.class);
178-
final Action0 second = mock(Action0.class);
179-
180-
scheduler.schedule(new Action0() {
181-
@Override
182-
public void call() {
183-
scheduler.schedule(first, 30, TimeUnit.MILLISECONDS);
184-
scheduler.schedule(second, 10, TimeUnit.MILLISECONDS);
185-
}
186-
});
187-
188-
InOrder inOrder = inOrder(first, second);
189-
190-
inOrder.verify(second, times(1)).call();
191-
inOrder.verify(first, times(1)).call();
192-
193-
194-
}
195-
196-
@Test
197-
public void testMixOfDelayedAndNonDelayedActions() {
198-
final CurrentThreadScheduler scheduler = new CurrentThreadScheduler();
199-
200-
final Action0 first = mock(Action0.class);
201-
final Action0 second = mock(Action0.class);
202-
final Action0 third = mock(Action0.class);
203-
final Action0 fourth = mock(Action0.class);
204-
205-
scheduler.schedule(new Action0() {
206-
@Override
207-
public void call() {
208-
scheduler.schedule(first);
209-
scheduler.schedule(second, 300, TimeUnit.MILLISECONDS);
210-
scheduler.schedule(third, 100, TimeUnit.MILLISECONDS);
211-
scheduler.schedule(fourth);
212-
}
213-
});
214-
215-
InOrder inOrder = inOrder(first, second, third, fourth);
216-
217-
inOrder.verify(first, times(1)).call();
218-
inOrder.verify(fourth, times(1)).call();
219-
inOrder.verify(third, times(1)).call();
220-
inOrder.verify(second, times(1)).call();
221-
222-
223-
}
224-
225-
}
226-
22799
}
Lines changed: 21 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
22
* Copyright 2013 Netflix, Inc.
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -15,96 +15,35 @@
1515
*/
1616
package rx.concurrency;
1717

18-
import static org.mockito.Mockito.*;
19-
20-
import java.util.concurrent.TimeUnit;
21-
22-
import org.junit.Test;
23-
import org.mockito.InOrder;
24-
2518
import rx.Scheduler;
2619
import rx.Subscription;
27-
import rx.util.functions.Action0;
2820
import rx.util.functions.Func2;
2921

22+
import java.util.concurrent.TimeUnit;
23+
3024
/**
3125
* Executes work immediately on the current thread.
3226
*/
3327
public final class ImmediateScheduler extends Scheduler {
34-
private static final ImmediateScheduler INSTANCE = new ImmediateScheduler();
35-
36-
public static ImmediateScheduler getInstance() {
37-
return INSTANCE;
38-
}
39-
40-
private ImmediateScheduler() {
41-
}
42-
43-
@Override
44-
public <T> Subscription schedule(T state, Func2<? super Scheduler, ? super T, ? extends Subscription> action) {
45-
return action.call(this, state);
46-
}
47-
48-
@Override
49-
public <T> Subscription schedule(T state, Func2<? super Scheduler, ? super T, ? extends Subscription> action, long dueTime, TimeUnit unit) {
50-
// since we are executing immediately on this thread we must cause this thread to sleep
51-
long execTime = now() + unit.toMillis(dueTime);
52-
53-
return schedule(state, new SleepingAction<T>(action, this, execTime));
54-
}
55-
56-
public static class UnitTest {
57-
58-
@Test
59-
public void testNestedActions() {
60-
final ImmediateScheduler scheduler = new ImmediateScheduler();
61-
62-
final Action0 firstStepStart = mock(Action0.class);
63-
final Action0 firstStepEnd = mock(Action0.class);
64-
65-
final Action0 secondStepStart = mock(Action0.class);
66-
final Action0 secondStepEnd = mock(Action0.class);
67-
68-
final Action0 thirdStepStart = mock(Action0.class);
69-
final Action0 thirdStepEnd = mock(Action0.class);
70-
71-
final Action0 firstAction = new Action0() {
72-
@Override
73-
public void call() {
74-
firstStepStart.call();
75-
firstStepEnd.call();
76-
}
77-
};
78-
final Action0 secondAction = new Action0() {
79-
@Override
80-
public void call() {
81-
secondStepStart.call();
82-
scheduler.schedule(firstAction);
83-
secondStepEnd.call();
84-
85-
}
86-
};
87-
final Action0 thirdAction = new Action0() {
88-
@Override
89-
public void call() {
90-
thirdStepStart.call();
91-
scheduler.schedule(secondAction);
92-
thirdStepEnd.call();
93-
}
94-
};
28+
private static final ImmediateScheduler INSTANCE = new ImmediateScheduler();
9529

96-
InOrder inOrder = inOrder(firstStepStart, firstStepEnd, secondStepStart, secondStepEnd, thirdStepStart, thirdStepEnd);
30+
public static ImmediateScheduler getInstance() {
31+
return INSTANCE;
32+
}
9733

98-
scheduler.schedule(thirdAction);
34+
ImmediateScheduler() {
35+
}
9936

100-
inOrder.verify(thirdStepStart, times(1)).call();
101-
inOrder.verify(secondStepStart, times(1)).call();
102-
inOrder.verify(firstStepStart, times(1)).call();
103-
inOrder.verify(firstStepEnd, times(1)).call();
104-
inOrder.verify(secondStepEnd, times(1)).call();
105-
inOrder.verify(thirdStepEnd, times(1)).call();
106-
}
37+
@Override
38+
public <T> Subscription schedule(T state, Func2<? super Scheduler, ? super T, ? extends Subscription> action) {
39+
return action.call(this, state);
40+
}
10741

108-
}
42+
@Override
43+
public <T> Subscription schedule(T state, Func2<? super Scheduler, ? super T, ? extends Subscription> action, long dueTime, TimeUnit unit) {
44+
// since we are executing immediately on this thread we must cause this thread to sleep
45+
long execTime = now() + unit.toMillis(dueTime);
10946

47+
return schedule(state, new SleepingAction<T>(action, this, execTime));
48+
}
11049
}

0 commit comments

Comments
 (0)