| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.internal.util; |
| 18 |
|
| 19 |
import android.os.Parcel; |
| 20 |
import android.platform.test.annotations.Presubmit; |
| 21 |
|
| 22 |
import static org.junit.Assert.assertEquals; |
| 23 |
import static org.junit.Assert.assertNull; |
| 24 |
|
| 25 |
import androidx.test.filters.SmallTest; |
| 26 |
|
| 27 |
import com.android.internal.util.Parcelling.BuiltIn.ForInstant; |
| 28 |
|
| 29 |
import org.junit.Test; |
| 30 |
import org.junit.runner.RunWith; |
| 31 |
import org.junit.runners.JUnit4; |
| 32 |
|
| 33 |
import java.time.Instant; |
| 34 |
|
| 35 |
|
| 36 |
@SmallTest |
| 37 |
@Presubmit |
| 38 |
@RunWith(JUnit4.class) |
| 39 |
public class ParcellingTests { |
| 40 |
|
| 41 |
private Parcel mParcel = Parcel.obtain(); |
| 42 |
|
| 43 |
@Test |
| 44 |
public void forInstant_normal() { |
| 45 |
testForInstant(Instant.ofEpochSecond(500L, 10)); |
| 46 |
} |
| 47 |
|
| 48 |
@Test |
| 49 |
public void forInstant_minimum() { |
| 50 |
testForInstant(Instant.MIN); |
| 51 |
} |
| 52 |
|
| 53 |
@Test |
| 54 |
public void forInstant_maximum() { |
| 55 |
testForInstant(Instant.MAX); |
| 56 |
} |
| 57 |
|
| 58 |
@Test |
| 59 |
public void forInstant_null() { |
| 60 |
testForInstant(null); |
| 61 |
} |
| 62 |
|
| 63 |
private void testForInstant(Instant instant) { |
| 64 |
Parcelling<Instant> parcelling = new ForInstant(); |
| 65 |
parcelling.parcel(instant, mParcel, 0); |
| 66 |
mParcel.setDataPosition(0); |
| 67 |
|
| 68 |
Instant created = parcelling.unparcel(mParcel); |
| 69 |
|
| 70 |
if (instant == null) { |
| 71 |
assertNull(created); |
| 72 |
} else { |
| 73 |
assertEquals(instant, created); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
} |