| 1 |
/* |
| 2 |
* Copyright (c) 2016-present, RxJava Contributors. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in |
| 5 |
* compliance with the License. You may obtain a copy of the License at |
| 6 |
* |
| 7 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
* |
| 9 |
* Unless required by applicable law or agreed to in writing, software distributed under the License is |
| 10 |
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See |
| 11 |
* the License for the specific language governing permissions and limitations under the License. |
| 12 |
*/ |
| 13 |
|
| 14 |
package io.reactivex.rxjava3.core; |
| 15 |
|
| 16 |
import static org.junit.Assert.*; |
| 17 |
|
| 18 |
import org.junit.Test; |
| 19 |
|
| 20 |
import io.reactivex.rxjava3.exceptions.TestException; |
| 21 |
|
| 22 |
public class NotificationTest extends RxJavaTest { |
| 23 |
|
| 24 |
@Test |
| 25 |
public void valueOfOnErrorIsNull() { |
| 26 |
Notification<Integer> notification = Notification.createOnError(new TestException()); |
| 27 |
|
| 28 |
assertNull(notification.getValue()); |
| 29 |
assertTrue(notification.getError().toString(), notification.getError() instanceof TestException); |
| 30 |
} |
| 31 |
|
| 32 |
@Test |
| 33 |
public void valueOfOnCompleteIsNull() { |
| 34 |
Notification<Integer> notification = Notification.createOnComplete(); |
| 35 |
|
| 36 |
assertNull(notification.getValue()); |
| 37 |
assertNull(notification.getError()); |
| 38 |
assertTrue(notification.isOnComplete()); |
| 39 |
} |
| 40 |
|
| 41 |
@Test |
| 42 |
public void notEqualsToObject() { |
| 43 |
Notification<Integer> n1 = Notification.createOnNext(0); |
| 44 |
assertNotEquals(0, n1); |
| 45 |
assertNotEquals(n1, 0); |
| 46 |
Notification<Integer> n2 = Notification.createOnError(new TestException()); |
| 47 |
assertNotEquals(0, n2); |
| 48 |
assertNotEquals(n2, 0); |
| 49 |
Notification<Integer> n3 = Notification.createOnComplete(); |
| 50 |
assertNotEquals(0, n3); |
| 51 |
assertNotEquals(n3, 0); |
| 52 |
} |
| 53 |
|
| 54 |
@Test |
| 55 |
public void twoEqual() { |
| 56 |
Notification<Integer> n1 = Notification.createOnNext(0); |
| 57 |
Notification<Integer> n2 = Notification.createOnNext(0); |
| 58 |
assertEquals(n1, n2); |
| 59 |
assertEquals(n2, n1); |
| 60 |
} |
| 61 |
|
| 62 |
@Test |
| 63 |
public void hashCodeIsTheInner() { |
| 64 |
Notification<Integer> n1 = Notification.createOnNext(1337); |
| 65 |
|
| 66 |
assertEquals(Integer.valueOf(1337).hashCode(), n1.hashCode()); |
| 67 |
|
| 68 |
assertEquals(0, Notification.createOnComplete().hashCode()); |
| 69 |
} |
| 70 |
|
| 71 |
@Test |
| 72 |
public void toStringPattern() { |
| 73 |
assertEquals("OnNextNotification[1]", Notification.createOnNext(1).toString()); |
| 74 |
assertEquals("OnErrorNotification[io.reactivex.rxjava3.exceptions.TestException]", Notification.createOnError(new TestException()).toString()); |
| 75 |
assertEquals("OnCompleteNotification", Notification.createOnComplete().toString()); |
| 76 |
} |
| 77 |
} |