From a88260722731256638112f53e80066dac516a690 Mon Sep 17 00:00:00 2001 From: Jordan Jozwiak Date: Thu, 2 Jan 2020 11:34:29 -0800 Subject: Put experimental tests in a tests/ directory The standard checkstyle rules only ignore tests if they are in tests/, test/, androidTest/, perftests/, or gts-tests/ Bug: 146803659 Test: atest ExperimentalCarServiceTests Change-Id: I7c281e937e919362d5ae4d805212ef6a15f8d55b --- .../experimentalcarservice_unit_test/Android.bp | 48 ------ .../AndroidManifest.xml | 31 ---- ...rDistractionExperimentalFeatureServiceTest.java | 189 --------------------- .../android/experimentalcar/FakeTimeSource.java | 44 ----- .../src/com/android/experimentalcar/FakeTimer.java | 44 ----- experimental/tests/Android.bp | 17 ++ .../experimentalcarservice_unit_test/Android.bp | 48 ++++++ .../AndroidManifest.xml | 31 ++++ ...rDistractionExperimentalFeatureServiceTest.java | 189 +++++++++++++++++++++ .../android/experimentalcar/FakeTimeSource.java | 44 +++++ .../src/com/android/experimentalcar/FakeTimer.java | 44 +++++ 11 files changed, 373 insertions(+), 356 deletions(-) delete mode 100644 experimental/experimentalcarservice_unit_test/Android.bp delete mode 100644 experimental/experimentalcarservice_unit_test/AndroidManifest.xml delete mode 100644 experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureServiceTest.java delete mode 100644 experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimeSource.java delete mode 100644 experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimer.java create mode 100644 experimental/tests/Android.bp create mode 100644 experimental/tests/experimentalcarservice_unit_test/Android.bp create mode 100644 experimental/tests/experimentalcarservice_unit_test/AndroidManifest.xml create mode 100644 experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureServiceTest.java create mode 100644 experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimeSource.java create mode 100644 experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimer.java (limited to 'experimental') diff --git a/experimental/experimentalcarservice_unit_test/Android.bp b/experimental/experimentalcarservice_unit_test/Android.bp deleted file mode 100644 index 891a151340..0000000000 --- a/experimental/experimentalcarservice_unit_test/Android.bp +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (C) 2019 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Unit tests for the experimental car service -android_test { - - name: "ExperimentalCarServiceTests", - - srcs: ["src/**/*.java"], - - platform_apis: true, - certificate: "platform", - - libs: [ - "android.car", - "android.test.runner", - "android.test.base", - "android.test.mock", - ], - - static_libs: [ - "androidx.test.core", - "androidx.test.ext.junit", - "androidx.test.rules", - "car-frameworks-service", - "mockito-target-extended", - "truth-prebuilt", - "experimentalcar-service-test-static-lib" - ], - - jni_libs: [ - "libdexmakerjvmtiagent", - "libstaticjvmtiagent", - ], - - instrumentation_for: "ExperimentalCarService", -} diff --git a/experimental/experimentalcarservice_unit_test/AndroidManifest.xml b/experimental/experimentalcarservice_unit_test/AndroidManifest.xml deleted file mode 100644 index 247d8f1681..0000000000 --- a/experimental/experimentalcarservice_unit_test/AndroidManifest.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - diff --git a/experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureServiceTest.java b/experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureServiceTest.java deleted file mode 100644 index 59ad9c519a..0000000000 --- a/experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureServiceTest.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.experimentalcar; - -import static com.google.common.truth.Truth.assertThat; - -import android.car.experimental.DriverAwarenessEvent; -import android.car.experimental.DriverAwarenessSupplierConfig; -import android.car.experimental.DriverAwarenessSupplierService; -import android.car.experimental.IDriverAwarenessSupplier; -import android.car.experimental.IDriverAwarenessSupplierCallback; -import android.content.Context; -import android.os.RemoteException; -import android.util.Pair; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import java.util.Arrays; - -@RunWith(MockitoJUnitRunner.class) -public class DriverDistractionExperimentalFeatureServiceTest { - - private static final long INITIAL_TIME = 1000L; - private static final long PREFERRED_SUPPLIER_STALENESS = 10L; - - private final IDriverAwarenessSupplier mFallbackSupplier = - new IDriverAwarenessSupplier.Stub() { - @Override - public void onReady() throws RemoteException { - } - - @Override - public void setCallback(IDriverAwarenessSupplierCallback callback) - throws RemoteException { - } - }; - private final DriverAwarenessSupplierConfig mFallbackConfig = new DriverAwarenessSupplierConfig( - DriverAwarenessSupplierService.NO_STALENESS); - - private final IDriverAwarenessSupplier mPreferredSupplier = - new IDriverAwarenessSupplier.Stub() { - @Override - public void onReady() throws RemoteException { - } - - @Override - public void setCallback(IDriverAwarenessSupplierCallback callback) - throws RemoteException { - } - }; - private final DriverAwarenessSupplierConfig mPreferredSupplierConfig = - new DriverAwarenessSupplierConfig(PREFERRED_SUPPLIER_STALENESS); - - @Mock - private Context mContext; - - private DriverDistractionExperimentalFeatureService mService; - private FakeTimeSource mTimeSource; - private FakeTimer mTimer; - - @Before - public void setUp() throws Exception { - mTimeSource = new FakeTimeSource(INITIAL_TIME); - mTimer = new FakeTimer(); - mService = new DriverDistractionExperimentalFeatureService(mContext, mTimeSource, mTimer); - } - - @After - public void tearDown() throws Exception { - if (mService != null) { - mService.release(); - } - } - - @Test - public void testHandleDriverAwarenessEvent_updatesCurrentValue_withLatestEvent() - throws Exception { - mService.setDriverAwarenessSuppliers(Arrays.asList( - new Pair<>(mFallbackSupplier, mFallbackConfig))); - - float firstEmittedEvent = 0.7f; - emitEvent(mFallbackSupplier, INITIAL_TIME + 1, firstEmittedEvent); - - assertThat(getCurrentAwarenessValue()).isEqualTo(firstEmittedEvent); - } - - @Test - public void testHandleDriverAwarenessEvent_hasPreferredEvent_ignoresFallbackEvent() - throws Exception { - mService.setDriverAwarenessSuppliers(Arrays.asList( - new Pair<>(mFallbackSupplier, mFallbackConfig), - new Pair<>(mPreferredSupplier, mPreferredSupplierConfig))); - - // emit an event from the preferred supplier before the fallback supplier - float preferredValue = 0.6f; - emitEvent(mPreferredSupplier, INITIAL_TIME + 1, preferredValue); - float fallbackValue = 0.7f; - emitEvent(mFallbackSupplier, INITIAL_TIME + 2, fallbackValue); - - // even though the fallback supplier has a more recent timestamp, it is not the current - // since the event from the preferred supplier is still fresh - assertThat(getCurrentAwarenessValue()).isEqualTo(preferredValue); - } - - @Test - public void testHandleDriverAwarenessEvent_ignoresOldEvents() throws Exception { - mService.setDriverAwarenessSuppliers(Arrays.asList( - new Pair<>(mFallbackSupplier, mFallbackConfig))); - - float firstEmittedEvent = 0.7f; - emitEvent(mFallbackSupplier, INITIAL_TIME + 1, firstEmittedEvent); - long oldTime = INITIAL_TIME - 100; - emitEvent(mFallbackSupplier, oldTime, 0.6f); - - // the event with the old timestamp shouldn't overwrite the value with a more recent - // timestamp - assertThat(getCurrentAwarenessValue()).isEqualTo(firstEmittedEvent); - } - - @Test - public void testPreferredAwarenessEvent_becomesStale_fallsBackToFallbackEvent() - throws Exception { - mService.setDriverAwarenessSuppliers(Arrays.asList( - new Pair<>(mFallbackSupplier, mFallbackConfig), - new Pair<>(mPreferredSupplier, mPreferredSupplierConfig))); - - // emit an event from the preferred supplier before the fallback supplier - float preferredValue = 0.6f; - long preferredEventTime = INITIAL_TIME + 1; - mTimeSource.setElapsedRealtime(preferredEventTime); - emitEvent(mPreferredSupplier, preferredEventTime, preferredValue); - float fallbackValue = 0.7f; - long fallbackEventTime = INITIAL_TIME + 2; - mTimeSource.setElapsedRealtime(fallbackEventTime); - emitEvent(mFallbackSupplier, fallbackEventTime, fallbackValue); - - // the preferred supplier still has a fresh event - assertThat(getCurrentAwarenessValue()).isEqualTo(preferredValue); - - // go into the future - mTimeSource.setElapsedRealtime(preferredEventTime + PREFERRED_SUPPLIER_STALENESS + 1); - mTimer.executePendingTask(); - - // the preferred supplier's data has become stale - assertThat(getCurrentAwarenessValue()).isEqualTo(fallbackValue); - } - - private float getCurrentAwarenessValue() { - return mService.getCurrentDriverAwareness().mAwarenessEvent.getAwarenessValue(); - } - - /** - * Handle an event as if it were emitted from the specified supplier with the specified time and - * value. - */ - private void emitEvent(IDriverAwarenessSupplier supplier, long time, float value) - throws RemoteException { - long maxStaleness; - if (supplier == mFallbackSupplier) { - maxStaleness = DriverAwarenessSupplierService.NO_STALENESS; - } else { - maxStaleness = PREFERRED_SUPPLIER_STALENESS; - } - mService.handleDriverAwarenessEvent( - new DriverDistractionExperimentalFeatureService.DriverAwarenessEventWrapper( - new DriverAwarenessEvent(time, value), - supplier, - maxStaleness)); - } -} diff --git a/experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimeSource.java b/experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimeSource.java deleted file mode 100644 index eb82e1eeb8..0000000000 --- a/experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimeSource.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.experimentalcar; - -/** - * Fake implementation of {@link ITimeSource}. - */ -public class FakeTimeSource implements ITimeSource { - - private long mElapsedRealtime; - - /** - * Create an instance of {@link FakeTimeSource} with an initial time. - */ - FakeTimeSource(long elapsedRealtime) { - mElapsedRealtime = elapsedRealtime; - } - - /** - * Set the value that will be returned {@link #elapsedRealtime()}. - */ - void setElapsedRealtime(long elapsedRealtime) { - mElapsedRealtime = elapsedRealtime; - } - - @Override - public long elapsedRealtime() { - return mElapsedRealtime; - } -} diff --git a/experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimer.java b/experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimer.java deleted file mode 100644 index 0bd9748324..0000000000 --- a/experimental/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimer.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.experimentalcar; - -import java.util.TimerTask; - -/** - * Fake implementation for {@link ITimer}. - */ -public class FakeTimer implements ITimer { - - private TimerTask mPendingTask; - - @Override - public void reset() { - mPendingTask = null; - } - - @Override - public void schedule(TimerTask task, long delay) { - mPendingTask = task; - } - - /** - * Immediately execute the scheduled task. - */ - void executePendingTask() { - mPendingTask.run(); - } -} diff --git a/experimental/tests/Android.bp b/experimental/tests/Android.bp new file mode 100644 index 0000000000..7996a89aa8 --- /dev/null +++ b/experimental/tests/Android.bp @@ -0,0 +1,17 @@ +// Copyright (C) 2020 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// + +// Include the sub-makefiles \ No newline at end of file diff --git a/experimental/tests/experimentalcarservice_unit_test/Android.bp b/experimental/tests/experimentalcarservice_unit_test/Android.bp new file mode 100644 index 0000000000..891a151340 --- /dev/null +++ b/experimental/tests/experimentalcarservice_unit_test/Android.bp @@ -0,0 +1,48 @@ +// Copyright (C) 2019 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Unit tests for the experimental car service +android_test { + + name: "ExperimentalCarServiceTests", + + srcs: ["src/**/*.java"], + + platform_apis: true, + certificate: "platform", + + libs: [ + "android.car", + "android.test.runner", + "android.test.base", + "android.test.mock", + ], + + static_libs: [ + "androidx.test.core", + "androidx.test.ext.junit", + "androidx.test.rules", + "car-frameworks-service", + "mockito-target-extended", + "truth-prebuilt", + "experimentalcar-service-test-static-lib" + ], + + jni_libs: [ + "libdexmakerjvmtiagent", + "libstaticjvmtiagent", + ], + + instrumentation_for: "ExperimentalCarService", +} diff --git a/experimental/tests/experimentalcarservice_unit_test/AndroidManifest.xml b/experimental/tests/experimentalcarservice_unit_test/AndroidManifest.xml new file mode 100644 index 0000000000..247d8f1681 --- /dev/null +++ b/experimental/tests/experimentalcarservice_unit_test/AndroidManifest.xml @@ -0,0 +1,31 @@ + + + + + + + + + + diff --git a/experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureServiceTest.java b/experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureServiceTest.java new file mode 100644 index 0000000000..59ad9c519a --- /dev/null +++ b/experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/DriverDistractionExperimentalFeatureServiceTest.java @@ -0,0 +1,189 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.experimentalcar; + +import static com.google.common.truth.Truth.assertThat; + +import android.car.experimental.DriverAwarenessEvent; +import android.car.experimental.DriverAwarenessSupplierConfig; +import android.car.experimental.DriverAwarenessSupplierService; +import android.car.experimental.IDriverAwarenessSupplier; +import android.car.experimental.IDriverAwarenessSupplierCallback; +import android.content.Context; +import android.os.RemoteException; +import android.util.Pair; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import java.util.Arrays; + +@RunWith(MockitoJUnitRunner.class) +public class DriverDistractionExperimentalFeatureServiceTest { + + private static final long INITIAL_TIME = 1000L; + private static final long PREFERRED_SUPPLIER_STALENESS = 10L; + + private final IDriverAwarenessSupplier mFallbackSupplier = + new IDriverAwarenessSupplier.Stub() { + @Override + public void onReady() throws RemoteException { + } + + @Override + public void setCallback(IDriverAwarenessSupplierCallback callback) + throws RemoteException { + } + }; + private final DriverAwarenessSupplierConfig mFallbackConfig = new DriverAwarenessSupplierConfig( + DriverAwarenessSupplierService.NO_STALENESS); + + private final IDriverAwarenessSupplier mPreferredSupplier = + new IDriverAwarenessSupplier.Stub() { + @Override + public void onReady() throws RemoteException { + } + + @Override + public void setCallback(IDriverAwarenessSupplierCallback callback) + throws RemoteException { + } + }; + private final DriverAwarenessSupplierConfig mPreferredSupplierConfig = + new DriverAwarenessSupplierConfig(PREFERRED_SUPPLIER_STALENESS); + + @Mock + private Context mContext; + + private DriverDistractionExperimentalFeatureService mService; + private FakeTimeSource mTimeSource; + private FakeTimer mTimer; + + @Before + public void setUp() throws Exception { + mTimeSource = new FakeTimeSource(INITIAL_TIME); + mTimer = new FakeTimer(); + mService = new DriverDistractionExperimentalFeatureService(mContext, mTimeSource, mTimer); + } + + @After + public void tearDown() throws Exception { + if (mService != null) { + mService.release(); + } + } + + @Test + public void testHandleDriverAwarenessEvent_updatesCurrentValue_withLatestEvent() + throws Exception { + mService.setDriverAwarenessSuppliers(Arrays.asList( + new Pair<>(mFallbackSupplier, mFallbackConfig))); + + float firstEmittedEvent = 0.7f; + emitEvent(mFallbackSupplier, INITIAL_TIME + 1, firstEmittedEvent); + + assertThat(getCurrentAwarenessValue()).isEqualTo(firstEmittedEvent); + } + + @Test + public void testHandleDriverAwarenessEvent_hasPreferredEvent_ignoresFallbackEvent() + throws Exception { + mService.setDriverAwarenessSuppliers(Arrays.asList( + new Pair<>(mFallbackSupplier, mFallbackConfig), + new Pair<>(mPreferredSupplier, mPreferredSupplierConfig))); + + // emit an event from the preferred supplier before the fallback supplier + float preferredValue = 0.6f; + emitEvent(mPreferredSupplier, INITIAL_TIME + 1, preferredValue); + float fallbackValue = 0.7f; + emitEvent(mFallbackSupplier, INITIAL_TIME + 2, fallbackValue); + + // even though the fallback supplier has a more recent timestamp, it is not the current + // since the event from the preferred supplier is still fresh + assertThat(getCurrentAwarenessValue()).isEqualTo(preferredValue); + } + + @Test + public void testHandleDriverAwarenessEvent_ignoresOldEvents() throws Exception { + mService.setDriverAwarenessSuppliers(Arrays.asList( + new Pair<>(mFallbackSupplier, mFallbackConfig))); + + float firstEmittedEvent = 0.7f; + emitEvent(mFallbackSupplier, INITIAL_TIME + 1, firstEmittedEvent); + long oldTime = INITIAL_TIME - 100; + emitEvent(mFallbackSupplier, oldTime, 0.6f); + + // the event with the old timestamp shouldn't overwrite the value with a more recent + // timestamp + assertThat(getCurrentAwarenessValue()).isEqualTo(firstEmittedEvent); + } + + @Test + public void testPreferredAwarenessEvent_becomesStale_fallsBackToFallbackEvent() + throws Exception { + mService.setDriverAwarenessSuppliers(Arrays.asList( + new Pair<>(mFallbackSupplier, mFallbackConfig), + new Pair<>(mPreferredSupplier, mPreferredSupplierConfig))); + + // emit an event from the preferred supplier before the fallback supplier + float preferredValue = 0.6f; + long preferredEventTime = INITIAL_TIME + 1; + mTimeSource.setElapsedRealtime(preferredEventTime); + emitEvent(mPreferredSupplier, preferredEventTime, preferredValue); + float fallbackValue = 0.7f; + long fallbackEventTime = INITIAL_TIME + 2; + mTimeSource.setElapsedRealtime(fallbackEventTime); + emitEvent(mFallbackSupplier, fallbackEventTime, fallbackValue); + + // the preferred supplier still has a fresh event + assertThat(getCurrentAwarenessValue()).isEqualTo(preferredValue); + + // go into the future + mTimeSource.setElapsedRealtime(preferredEventTime + PREFERRED_SUPPLIER_STALENESS + 1); + mTimer.executePendingTask(); + + // the preferred supplier's data has become stale + assertThat(getCurrentAwarenessValue()).isEqualTo(fallbackValue); + } + + private float getCurrentAwarenessValue() { + return mService.getCurrentDriverAwareness().mAwarenessEvent.getAwarenessValue(); + } + + /** + * Handle an event as if it were emitted from the specified supplier with the specified time and + * value. + */ + private void emitEvent(IDriverAwarenessSupplier supplier, long time, float value) + throws RemoteException { + long maxStaleness; + if (supplier == mFallbackSupplier) { + maxStaleness = DriverAwarenessSupplierService.NO_STALENESS; + } else { + maxStaleness = PREFERRED_SUPPLIER_STALENESS; + } + mService.handleDriverAwarenessEvent( + new DriverDistractionExperimentalFeatureService.DriverAwarenessEventWrapper( + new DriverAwarenessEvent(time, value), + supplier, + maxStaleness)); + } +} diff --git a/experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimeSource.java b/experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimeSource.java new file mode 100644 index 0000000000..eb82e1eeb8 --- /dev/null +++ b/experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimeSource.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.experimentalcar; + +/** + * Fake implementation of {@link ITimeSource}. + */ +public class FakeTimeSource implements ITimeSource { + + private long mElapsedRealtime; + + /** + * Create an instance of {@link FakeTimeSource} with an initial time. + */ + FakeTimeSource(long elapsedRealtime) { + mElapsedRealtime = elapsedRealtime; + } + + /** + * Set the value that will be returned {@link #elapsedRealtime()}. + */ + void setElapsedRealtime(long elapsedRealtime) { + mElapsedRealtime = elapsedRealtime; + } + + @Override + public long elapsedRealtime() { + return mElapsedRealtime; + } +} diff --git a/experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimer.java b/experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimer.java new file mode 100644 index 0000000000..0bd9748324 --- /dev/null +++ b/experimental/tests/experimentalcarservice_unit_test/src/com/android/experimentalcar/FakeTimer.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.experimentalcar; + +import java.util.TimerTask; + +/** + * Fake implementation for {@link ITimer}. + */ +public class FakeTimer implements ITimer { + + private TimerTask mPendingTask; + + @Override + public void reset() { + mPendingTask = null; + } + + @Override + public void schedule(TimerTask task, long delay) { + mPendingTask = task; + } + + /** + * Immediately execute the scheduled task. + */ + void executePendingTask() { + mPendingTask.run(); + } +} -- cgit v1.2.3