TelephonyManager.listen()をテストしたい
TelephonyManager.listen()の結果をユニットテストしようとしたのですが、うまくいきませんでした。試したことをメモしておきます。
listen()をオーバーライドしたTelephonyManagerのサブクラスを用意して、ContextのモックがgetSystemService()でそのサブクラスを返せば、ユニットテストできそうです。
TelephonyManager.java
/** @hide */ public TelephonyManager(Context context) { mContext = context; mRegistry = ITelephonyRegistry.Stub.asInterface(ServiceManager.getService( "telephony.registry")); } /** @hide */ private TelephonyManager() { } private static TelephonyManager sInstance = new TelephonyManager(); /** @hide */ public static TelephonyManager getDefault() { return sInstance; }