Skip to content

Commit 89d2803

Browse files
Thomas NieldThomas Nield
authored andcommitted
Merge branch '2.11.x' of https://github.com/ReactiveX/RxJavaFX into 2.11.x
2 parents a2a55fe + 6f1e480 commit 89d2803

File tree

6 files changed

+56
-13
lines changed

6 files changed

+56
-13
lines changed

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ task sourcesJar(type: Jar, dependsOn: classes) {
7070
classifier = "sources"
7171
from sourceSets.main.allSource
7272
}
73-
7473
artifacts {
7574
archives jar
7675
}

buildViaTravis.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@ export GRADLE_OPTS=-Xmx1024m
99
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
1010
echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]"
1111
./gradlew -PreleaseMode=pr build
12-
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then
13-
echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']'
14-
./gradlew -PreleaseMode=branch -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" build --stacktrace
1512
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
1613
echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG']'
1714
./gradlew -PreleaseMode=full -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" build --stacktrace
1815
else
1916
echo -e 'WARN: Should not be here => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG'] Pull Request ['$TRAVIS_PULL_REQUEST']'
20-
fi
17+
fi

gradle/buildViaTravis.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then
55
echo -e "Build Pull Request #$TRAVIS_PULL_REQUEST => Branch [$TRAVIS_BRANCH]"
66
./gradlew -Prelease.useLastTag=true build
7-
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" == "" ]; then
8-
echo -e 'Build Branch with Snapshot => Branch ['$TRAVIS_BRANCH']'
9-
./gradlew -Prelease.travisci=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" build snapshot --stacktrace
107
elif [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_TAG" != "" ]; then
118
echo -e 'Build Branch for Release => Branch ['$TRAVIS_BRANCH'] Tag ['$TRAVIS_TAG']'
129
./gradlew -Prelease.travisci=true -Prelease.useLastTag=true -PbintrayUser="${bintrayUser}" -PbintrayKey="${bintrayKey}" -PsonatypeUsername="${sonatypeUsername}" -PsonatypePassword="${sonatypePassword}" final --stacktrace

src/main/java/io/reactivex/rxjavafx/sources/Change.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package io.reactivex.rxjavafx.sources;
1717

18+
import java.util.Objects;
19+
1820
public final class Change<T> {
1921
private final T oldVal;
2022
private final T newVal;
@@ -29,4 +31,26 @@ public T getOldVal() {
2931
public T getNewVal() {
3032
return newVal;
3133
}
34+
35+
@Override
36+
public boolean equals(Object o) {
37+
if (this == o) return true;
38+
if (o == null || getClass() != o.getClass()) return false;
39+
Change<?> change = (Change<?>) o;
40+
return Objects.equals(oldVal, change.oldVal) &&
41+
Objects.equals(newVal, change.newVal);
42+
}
43+
44+
@Override
45+
public int hashCode() {
46+
return Objects.hash(oldVal, newVal);
47+
}
48+
49+
@Override
50+
public String toString() {
51+
return "Change{" +
52+
"oldVal=" + oldVal +
53+
", newVal=" + newVal +
54+
'}';
55+
}
3256
}

src/main/java/io/reactivex/rxjavafx/sources/ObservableValueSource.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626

2727
public class ObservableValueSource {
2828

29+
2930
public static <T> Observable<T> fromObservableValue(final ObservableValue<T> fxObservable) {
3031
return Observable.create((ObservableEmitter<T> emitter) -> {
3132
if (fxObservable.getValue() != null)
3233
emitter.onNext(fxObservable.getValue());
3334

3435
final ChangeListener<T> listener = (observableValue, prev, current) -> {
35-
if (current != null)
36-
emitter.onNext(current);
36+
emitter.onNext(current);
3737
};
3838

3939
fxObservable.addListener(listener);
@@ -80,8 +80,7 @@ public static <T> Observable<Optional<T>> fromNullableObservableValue(final Obse
8080
public static <T> Observable<Change<T>> fromObservableValueChanges(final ObservableValue<T> fxObservable) {
8181
return Observable.create((ObservableEmitter<Change<T>> emitter) -> {
8282
final ChangeListener<T> listener = (observableValue, prev, current) -> {
83-
if (current != null)
84-
emitter.onNext(new Change<>(prev,current));
83+
emitter.onNext(new Change<>(prev,current));
8584
};
8685

8786
fxObservable.addListener(listener);

src/test/java/io/reactivex/rxjavafx/sources/JavaFxObservableTest.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javafx.collections.FXCollections;
2626
import javafx.collections.ObservableList;
2727
import javafx.util.Duration;
28+
import org.junit.BeforeClass;
2829
import org.junit.Test;
2930

3031
import java.util.Arrays;
@@ -35,6 +36,11 @@
3536

3637
public final class JavaFxObservableTest {
3738

39+
@BeforeClass
40+
public static void initJFX() {
41+
javafx.application.Platform.startup(() ->{});
42+
}
43+
3844
@Test
3945
public void testIntervalSource() {
4046

@@ -87,6 +93,27 @@ public void testListPropertyEmitOnChanged() {
8793

8894
testObserver.assertValueCount(3);
8995
}
96+
@Test
97+
public void testRxObservableChanges() {
98+
Property<String> sourceProperty = new SimpleStringProperty();
99+
Observable<Change<String>> emissions = JavaFxObservable.changesOf(sourceProperty).take(4);
100+
101+
TestObserver<Change<String>> testObserver = new TestObserver<>();
102+
103+
emissions.subscribe(testObserver);
104+
105+
sourceProperty.setValue("Alpha");
106+
sourceProperty.setValue("Beta");
107+
sourceProperty.setValue(null);
108+
sourceProperty.setValue("Gamma");
109+
110+
testObserver.assertValues(
111+
new Change<>(null, "Alpha"),
112+
new Change<>("Alpha", "Beta"),
113+
new Change<>("Beta", null),
114+
new Change<>(null, "Gamma")
115+
);
116+
}
90117

91118
@Test
92119
public void testRxObservableListAdds() {
@@ -101,7 +128,7 @@ public void testRxObservableListAdds() {
101128
.take(3)
102129
.toList()
103130
.toObservable()
104-
.subscribe(l -> assertTrue(l.containsAll(Arrays.asList("Alpha","Beta","Gamma"))),Throwable::printStackTrace,gate::countDown);
131+
.subscribe(l -> assertTrue(l.equals(Arrays.asList("Alpha", "Beta", "Gamma"))), Throwable::printStackTrace, gate::countDown);;
105132

106133
Platform.runLater(() -> {
107134
sourceList.add("Alpha");

0 commit comments

Comments
 (0)