File tree Expand file tree Collapse file tree 6 files changed +84
-4
lines changed
main/java/io/reactivex/internal/operators
test/java/io/reactivex/internal/operators Expand file tree Collapse file tree 6 files changed +84
-4
lines changed Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ public void onError(Throwable t) {
97
97
@ Override
98
98
public void onComplete () {
99
99
s = SubscriptionHelper .CANCELLED ;
100
- if (index <= count && !done ) {
100
+ if (!done ) {
101
101
done = true ;
102
102
actual .onComplete ();
103
103
}
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ public void onError(Throwable t) {
103
103
@ Override
104
104
public void onComplete () {
105
105
s = SubscriptionHelper .CANCELLED ;
106
- if (index <= count && !done ) {
106
+ if (!done ) {
107
107
done = true ;
108
108
109
109
T v = defaultValue ;
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ public void onError(Throwable t) {
98
98
99
99
@ Override
100
100
public void onComplete () {
101
- if (index <= count && !done ) {
101
+ if (!done ) {
102
102
done = true ;
103
103
actual .onComplete ();
104
104
}
Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ public void onError(Throwable t) {
99
99
100
100
@ Override
101
101
public void onComplete () {
102
- if (index <= count && !done ) {
102
+ if (!done ) {
103
103
done = true ;
104
104
105
105
T v = defaultValue ;
Original file line number Diff line number Diff line change @@ -135,4 +135,44 @@ public void elementAtOrErrorError() {
135
135
.assertErrorMessage ("error" )
136
136
.assertError (RuntimeException .class );
137
137
}
138
+
139
+ @ Test
140
+ public void elementAtIndex0OnEmptySource () {
141
+ Flowable .empty ()
142
+ .elementAt (0 )
143
+ .test ()
144
+ .assertResult ();
145
+ }
146
+
147
+ @ Test
148
+ public void elementAtIndex0WithDefaultOnEmptySource () {
149
+ Flowable .empty ()
150
+ .elementAt (0 , 5 )
151
+ .test ()
152
+ .assertResult (5 );
153
+ }
154
+
155
+ @ Test
156
+ public void elementAtIndex1OnEmptySource () {
157
+ Flowable .empty ()
158
+ .elementAt (1 )
159
+ .test ()
160
+ .assertResult ();
161
+ }
162
+
163
+ @ Test
164
+ public void elementAtIndex1WithDefaultOnEmptySource () {
165
+ Flowable .empty ()
166
+ .elementAt (1 , 10 )
167
+ .test ()
168
+ .assertResult (10 );
169
+ }
170
+
171
+ @ Test
172
+ public void elementAtOrErrorIndex1OnEmptySource () {
173
+ Flowable .empty ()
174
+ .elementAtOrError (1 )
175
+ .test ()
176
+ .assertFailure (NoSuchElementException .class );
177
+ }
138
178
}
Original file line number Diff line number Diff line change @@ -126,4 +126,44 @@ public void elementAtOrErrorError() {
126
126
.assertErrorMessage ("error" )
127
127
.assertError (RuntimeException .class );
128
128
}
129
+
130
+ @ Test
131
+ public void elementAtIndex0OnEmptySource () {
132
+ Observable .empty ()
133
+ .elementAt (0 )
134
+ .test ()
135
+ .assertResult ();
136
+ }
137
+
138
+ @ Test
139
+ public void elementAtIndex0WithDefaultOnEmptySource () {
140
+ Observable .empty ()
141
+ .elementAt (0 , 5 )
142
+ .test ()
143
+ .assertResult (5 );
144
+ }
145
+
146
+ @ Test
147
+ public void elementAtIndex1OnEmptySource () {
148
+ Observable .empty ()
149
+ .elementAt (1 )
150
+ .test ()
151
+ .assertResult ();
152
+ }
153
+
154
+ @ Test
155
+ public void elementAtIndex1WithDefaultOnEmptySource () {
156
+ Observable .empty ()
157
+ .elementAt (1 , 10 )
158
+ .test ()
159
+ .assertResult (10 );
160
+ }
161
+
162
+ @ Test
163
+ public void elementAtOrErrorIndex1OnEmptySource () {
164
+ Observable .empty ()
165
+ .elementAtOrError (1 )
166
+ .test ()
167
+ .assertFailure (NoSuchElementException .class );
168
+ }
129
169
}
You can’t perform that action at this time.
0 commit comments