Skip to content

Commit

Permalink
Merge pull request #274 from benjchristensen/0.9-cleanup
Browse files Browse the repository at this point in the history
0.9 cleanup
  • Loading branch information
benjchristensen committed May 16, 2013
2 parents 400bdf4 + cb0fc9d commit 448d778
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def class ObservableTests {

@Test
public void testMap1() {
new TestFactory().getObservable().map({v -> 'say' + v}).subscribe({ result -> a.received(result)});
verify(a, times(1)).received("sayhello_1");
Observable.from(1).map({v -> 'hello_' + v}).subscribe({ result -> a.received(result)});
verify(a, times(1)).received("hello_1");
}

@Test
Expand Down
3 changes: 2 additions & 1 deletion rxjava-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6

dependencies {
compile 'org.slf4j:slf4j-api:1.7.0'
provided 'junit:junit-dep:4.10'
provided 'org.mockito:mockito-core:1.8.5'
}
Expand Down Expand Up @@ -49,5 +48,7 @@ jar {
instruction 'Bundle-DocURL', 'https://github.com/Netflix/RxJava'
instruction 'Import-Package', '!org.junit,!junit.framework,!org.mockito.*,*'
}
// commenting out for now as it's breaking the rxjava-scala build and I can't figure out why
// exclude('**/*$UnitTest*')
}

52 changes: 26 additions & 26 deletions rxjava-core/src/main/java/rx/observables/BlockingObservable.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Subscription call(Observer<T> observer) {
/**
* Returns an iterator that iterates all values of the observable.
*
* @param that
* @param source
* an observable sequence to get an iterator for.
* @param <T>
* the type of source.
Expand All @@ -57,7 +57,7 @@ public static <T> Iterator<T> toIterator(Observable<T> source) {
/**
* Returns the last element of an observable sequence with a specified source.
*
* @param that
* @param source
* the source Observable
* @return the last element in the observable sequence.
*/
Expand All @@ -68,7 +68,7 @@ public static <T> T last(final Observable<T> source) {
/**
* Returns the last element of an observable sequence that matches the predicate.
*
* @param that
* @param source
* the source Observable
* @param predicate
* a predicate function to evaluate for elements in the sequence.
Expand All @@ -81,7 +81,7 @@ public static <T> T last(final Observable<T> source, final Func1<T, Boolean> pre
/**
* Returns the last element of an observable sequence that matches the predicate.
*
* @param that
* @param source
* the source Observable
* @param predicate
* a predicate function to evaluate for elements in the sequence.
Expand Down Expand Up @@ -198,7 +198,7 @@ private static <T> T _singleOrDefault(BlockingObservable<T> source, boolean hasD
/**
* Returns the only element of an observable sequence and throws an exception if there is not exactly one element in the observable sequence.
*
* @param that
* @param source
* the source Observable
* @return The single element in the observable sequence.
* @throws IllegalStateException
Expand All @@ -211,7 +211,7 @@ public static <T> T single(Observable<T> source) {
/**
* Returns the only element of an observable sequence that matches the predicate and throws an exception if there is not exactly one element in the observable sequence.
*
* @param that
* @param source
* the source Observable
* @param predicate
* A predicate function to evaluate for elements in the sequence.
Expand All @@ -226,7 +226,7 @@ public static <T> T single(Observable<T> source, Func1<T, Boolean> predicate) {
/**
* Returns the only element of an observable sequence that matches the predicate and throws an exception if there is not exactly one element in the observable sequence.
*
* @param that
* @param source
* the source Observable
* @param predicate
* A predicate function to evaluate for elements in the sequence.
Expand All @@ -241,7 +241,7 @@ public static <T> T single(Observable<T> source, Object predicate) {
/**
* Returns the only element of an observable sequence, or a default value if the observable sequence is empty.
*
* @param that
* @param source
* the source Observable
* @param defaultValue
* default value for a sequence.
Expand All @@ -254,7 +254,7 @@ public static <T> T singleOrDefault(Observable<T> source, T defaultValue) {
/**
* Returns the only element of an observable sequence that matches the predicate, or a default value if no value is found.
*
* @param that
* @param source
* the source Observable
* @param defaultValue
* default value for a sequence.
Expand All @@ -269,7 +269,7 @@ public static <T> T singleOrDefault(Observable<T> source, T defaultValue, Func1<
/**
* Returns the only element of an observable sequence that matches the predicate, or a default value if no value is found.
*
* @param that
* @param source
* the source Observable
* @param defaultValue
* default value for a sequence.
Expand All @@ -286,7 +286,7 @@ public static <T> T singleOrDefault(Observable<T> source, T defaultValue, Object
* <p>
* This will throw an exception if the Observable emits more than 1 value. If more than 1 are expected then use <code>toList().toFuture()</code>.
*
* @param that
* @param source
* the source Observable
* @return a Future that expects a single item emitted by the source Observable
*/
Expand All @@ -297,7 +297,7 @@ public static <T> Future<T> toFuture(final Observable<T> source) {
/**
* Converts an observable sequence to an Iterable.
*
* @param that
* @param source
* the source Observable
* @return Observable converted to Iterable.
*/
Expand Down Expand Up @@ -565,7 +565,7 @@ public void testLastEmptyObservable() {

@Test
public void testLastOrDefault() {
BlockingObservable<Integer> observable = BlockingObservable.from(toObservable(1, 0, -1));
BlockingObservable<Integer> observable = BlockingObservable.from(from(1, 0, -1));
int last = observable.lastOrDefault(-100, new Func1<Integer, Boolean>() {
@Override
public Boolean call(Integer args) {
Expand All @@ -577,19 +577,19 @@ public Boolean call(Integer args) {

@Test
public void testLastOrDefault1() {
BlockingObservable<String> observable = BlockingObservable.from(toObservable("one", "two", "three"));
BlockingObservable<String> observable = BlockingObservable.from(from("one", "two", "three"));
assertEquals("three", observable.lastOrDefault("default"));
}

@Test
public void testLastOrDefault2() {
BlockingObservable<Object> observable = BlockingObservable.from(toObservable());
BlockingObservable<Object> observable = BlockingObservable.from(from());
assertEquals("default", observable.lastOrDefault("default"));
}

@Test
public void testLastOrDefaultWithPredicate() {
BlockingObservable<Integer> observable = BlockingObservable.from(toObservable(1, 0, -1));
BlockingObservable<Integer> observable = BlockingObservable.from(from(1, 0, -1));
int last = observable.lastOrDefault(0, new Func1<Integer, Boolean>() {
@Override
public Boolean call(Integer args) {
Expand All @@ -602,7 +602,7 @@ public Boolean call(Integer args) {

@Test
public void testLastOrDefaultWrongPredicate() {
BlockingObservable<Integer> observable = BlockingObservable.from(toObservable(-1, -2, -3));
BlockingObservable<Integer> observable = BlockingObservable.from(from(-1, -2, -3));
int last = observable.lastOrDefault(0, new Func1<Integer, Boolean>() {
@Override
public Boolean call(Integer args) {
Expand All @@ -625,19 +625,19 @@ public Boolean call(String s) {
}

public void testSingle() {
BlockingObservable<String> observable = BlockingObservable.from(toObservable("one"));
BlockingObservable<String> observable = BlockingObservable.from(from("one"));
assertEquals("one", observable.single());
}

@Test
public void testSingleDefault() {
BlockingObservable<Object> observable = BlockingObservable.from(toObservable());
BlockingObservable<Object> observable = BlockingObservable.from(from());
assertEquals("default", observable.singleOrDefault("default"));
}

@Test(expected = IllegalStateException.class)
public void testSingleDefaultPredicateMatchesMoreThanOne() {
BlockingObservable.from(toObservable("one", "two")).singleOrDefault("default", new Func1<String, Boolean>() {
BlockingObservable.from(from("one", "two")).singleOrDefault("default", new Func1<String, Boolean>() {
@Override
public Boolean call(String args) {
return args.length() == 3;
Expand All @@ -647,7 +647,7 @@ public Boolean call(String args) {

@Test
public void testSingleDefaultPredicateMatchesNothing() {
BlockingObservable<String> observable = BlockingObservable.from(toObservable("one", "two"));
BlockingObservable<String> observable = BlockingObservable.from(from("one", "two"));
String result = observable.singleOrDefault("default", new Func1<String, Boolean>() {
@Override
public Boolean call(String args) {
Expand All @@ -659,13 +659,13 @@ public Boolean call(String args) {

@Test(expected = IllegalStateException.class)
public void testSingleDefaultWithMoreThanOne() {
BlockingObservable<String> observable = BlockingObservable.from(toObservable("one", "two", "three"));
BlockingObservable<String> observable = BlockingObservable.from(from("one", "two", "three"));
observable.singleOrDefault("default");
}

@Test
public void testSingleWithPredicateDefault() {
BlockingObservable<String> observable = BlockingObservable.from(toObservable("one", "two", "four"));
BlockingObservable<String> observable = BlockingObservable.from(from("one", "two", "four"));
assertEquals("four", observable.single(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
Expand All @@ -676,13 +676,13 @@ public Boolean call(String s) {

@Test(expected = IllegalStateException.class)
public void testSingleWrong() {
BlockingObservable<Integer> observable = BlockingObservable.from(toObservable(1, 2));
BlockingObservable<Integer> observable = BlockingObservable.from(from(1, 2));
observable.single();
}

@Test(expected = IllegalStateException.class)
public void testSingleWrongPredicate() {
BlockingObservable<Integer> observable = BlockingObservable.from(toObservable(-1));
BlockingObservable<Integer> observable = BlockingObservable.from(from(-1));
observable.single(new Func1<Integer, Boolean>() {
@Override
public Boolean call(Integer args) {
Expand All @@ -693,7 +693,7 @@ public Boolean call(Integer args) {

@Test
public void testToIterable() {
BlockingObservable<String> obs = BlockingObservable.from(toObservable("one", "two", "three"));
BlockingObservable<String> obs = BlockingObservable.from(from("one", "two", "three"));

Iterator<String> it = obs.toIterable().iterator();

Expand Down
Loading

0 comments on commit 448d778

Please sign in to comment.