### Question:
DownloadStrategy { public void inspectNetworkOnWifi(@NonNull DownloadTask task) throws IOException { if (isHasAccessNetworkStatePermission == null) { isHasAccessNetworkStatePermission = Util .checkPermission(Manifest.permission.ACCESS_NETWORK_STATE); } if (!task.isWifiRequired()) return; if (!isHasAccessNetworkStatePermission) { throw new IOException("required for access network state but don't have the " + "permission of Manifest.permission.ACCESS_NETWORK_STATE, please declare this " + "permission first on your AndroidManifest, so we can handle the case of " + "downloading required wifi state."); } if (manager == null) { manager = (ConnectivityManager) OkDownload.with().context() .getSystemService(Context.CONNECTIVITY_SERVICE); } if (Util.isNetworkNotOnWifiType(manager)) { throw new NetworkPolicyException(); } }  ResumeAvailableResponseCheck resumeAvailableResponseCheck(
            DownloadConnection.Connected connected,
            int blockIndex,
            BreakpointInfo info); int determineBlockCount(@NonNull DownloadTask task, long totalLength); long reuseIdledSameInfoThresholdBytes(); boolean inspectAnotherSameInfo(@NonNull DownloadTask task, @NonNull BreakpointInfo info,
                                          long instanceLength); boolean isUseMultiBlock(final boolean isAcceptRange); void inspectFilenameFromResume(@NonNull String filenameOnStore,
                                          @NonNull DownloadTask task); void validFilenameFromResponse(@Nullable String responseFileName,
                                          @NonNull DownloadTask task,
                                          @NonNull BreakpointInfo info); boolean validFilenameFromStore(@NonNull DownloadTask task); void validInfoOnCompleted(@NonNull DownloadTask task, @NonNull DownloadStore store); @Nullable ResumeFailedCause getPreconditionFailedCause(int responseCode,
                                                                  boolean isAlreadyProceed,
                                                                  @NonNull BreakpointInfo info,
                                                                  @Nullable String responseEtag); boolean isServerCanceled(int responseCode, boolean isAlreadyProceed); void inspectNetworkAvailable(); void inspectNetworkOnWifi(@NonNull DownloadTask task);  }### Answer:
@Test public void inspectNetworkOnWifi() throws IOException { final DownloadTask task = mock(DownloadTask.class); when(task.isWifiRequired()).thenReturn(true); final Context context = mock(Context.class); final OkDownload okDownload = OkDownload.with(); doReturn(context).when(okDownload).context(); doReturn(PackageManager.PERMISSION_DENIED).when(context) .checkCallingOrSelfPermission(anyString()); thrown.expect(IOException.class); thrown.expectMessage("required for access network state but don't have the " + "permission of Manifest.permission.ACCESS_NETWORK_STATE, please declare this " + "permission first on your AndroidManifest, so we can handle the case of " + "downloading required wifi state."); strategy.inspectNetworkOnWifi(task); strategy.isHasAccessNetworkStatePermission = true; final ConnectivityManager manager = mock(ConnectivityManager.class); doReturn(manager).when(context).getSystemService(eq(Context.CONNECTIVITY_SERVICE)); doReturn(null).when(manager).getActiveNetworkInfo(); thrown.expect(NetworkPolicyException.class); thrown.expectMessage("Only allows downloading this task on the wifi network type!"); strategy.inspectNetworkOnWifi(task); final NetworkInfo info = mock(NetworkInfo.class); doReturn(info).when(manager).getActiveNetworkInfo(); doReturn(ConnectivityManager.TYPE_WIFI).when(info).getType(); strategy.inspectNetworkOnWifi(task); }