| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.server; |
| 18 |
|
| 19 |
import static com.google.common.truth.Truth.assertThat; |
| 20 |
|
| 21 |
import static org.mockito.Mockito.spy; |
| 22 |
|
| 23 |
import android.content.Intent; |
| 24 |
import android.os.IBinder; |
| 25 |
import android.os.RemoteCallback; |
| 26 |
import android.service.watchdog.ExplicitHealthCheckService; |
| 27 |
import android.service.watchdog.IExplicitHealthCheckService; |
| 28 |
|
| 29 |
import org.junit.Before; |
| 30 |
import org.junit.Test; |
| 31 |
|
| 32 |
import java.util.concurrent.CountDownLatch; |
| 33 |
|
| 34 |
public class ExplicitHealthCheckServiceTest { |
| 35 |
|
| 36 |
private ExplicitHealthCheckService mExplicitHealthCheckService; |
| 37 |
private static final String PACKAGE_NAME = "com.test.package"; |
| 38 |
|
| 39 |
@Before |
| 40 |
public void setup() throws Exception { |
| 41 |
mExplicitHealthCheckService = spy(ExplicitHealthCheckService.class); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
@Test |
| 49 |
public void testNotifyHealthCheckPassed() throws Exception { |
| 50 |
IBinder binder = mExplicitHealthCheckService.onBind(new Intent()); |
| 51 |
CountDownLatch countDownLatch = new CountDownLatch(1); |
| 52 |
RemoteCallback callback = new RemoteCallback(result -> { |
| 53 |
assertThat(result.get(ExplicitHealthCheckService.EXTRA_HEALTH_CHECK_PASSED_PACKAGE)) |
| 54 |
.isEqualTo(PACKAGE_NAME); |
| 55 |
countDownLatch.countDown(); |
| 56 |
}); |
| 57 |
IExplicitHealthCheckService.Stub.asInterface(binder).setCallback(callback); |
| 58 |
mExplicitHealthCheckService.notifyHealthCheckPassed(PACKAGE_NAME); |
| 59 |
countDownLatch.await(); |
| 60 |
} |
| 61 |
} |