diff options
Diffstat (limited to 'tests/src/com/cyngn/audiofx/util/BaseAudioFxServiceInstrumentationTest.java')
-rw-r--r-- | tests/src/com/cyngn/audiofx/util/BaseAudioFxServiceInstrumentationTest.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/src/com/cyngn/audiofx/util/BaseAudioFxServiceInstrumentationTest.java b/tests/src/com/cyngn/audiofx/util/BaseAudioFxServiceInstrumentationTest.java new file mode 100644 index 0000000..e882c9d --- /dev/null +++ b/tests/src/com/cyngn/audiofx/util/BaseAudioFxServiceInstrumentationTest.java @@ -0,0 +1,59 @@ +package com.cyngn.audiofx.util; + +import android.content.Context; +import android.content.Intent; +import android.media.audiofx.AudioEffect; +import android.os.IBinder; +import android.support.test.InstrumentationRegistry; +import android.support.test.rule.ServiceTestRule; +import android.support.test.runner.AndroidJUnit4; +import com.cyngn.audiofx.service.AudioFxService; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.concurrent.TimeoutException; + +import static org.junit.Assert.*; + +/** + * Created by roman on 3/1/16. + */ +@RunWith(AndroidJUnit4.class) +public abstract class BaseAudioFxServiceInstrumentationTest { + + private static final int MAX_ITERATION = 100; + + protected AudioFxService.LocalBinder mService; + + @Rule + public ServiceTestRule mServiceRule = new ServiceTestRule(); + + protected void setupService() throws TimeoutException { + int it = 0; + + /** + * lol + * https://code.google.com/p/android/issues/detail?id=180396 + */ + IBinder binder; + while((binder = mServiceRule.bindService( + new Intent(InstrumentationRegistry.getTargetContext(), + AudioFxService.class))) == null && it < MAX_ITERATION){ + it++; + } + mService = (AudioFxService.LocalBinder) binder; + assertNotNull(mService); + } + + protected final Context getContext() { + return InstrumentationRegistry.getContext(); + } + + protected final Context getTargetContext() { + return InstrumentationRegistry.getTargetContext(); + } + +} |