DefaultTypeFaceProvider implements ITypeFaceProvider { @Override @Nullable public Typeface getTypeFaceFromAssets(final String fontFilePath) { try { return Typeface.createFromAsset(mContext.getAssets(), fontFilePath); } catch (RuntimeException e) { Log.e(DefaultTypeFaceProvider.class.getName(), e.getMessage()); } return null; } DefaultTypeFaceProvider(final Context context); @Override @Nullable Typeface getTypeFaceFromAssets(final String fontFilePath);  }
@Test public void getTypeFaceFromAssetsTest() throws Exception { PowerMockito.mockStatic(Typeface.class); when(mMockContext.getAssets()).thenReturn(mMockedAssetManager); when(Typeface.createFromAsset(mMockedAssetManager, ASSET_PATH)).thenReturn(mMockedTypeFace); Typeface typeface = mTypeFaceProvider.getTypeFaceFromAssets(ASSET_PATH); PowerMockito.verifyStatic(times(1)); assert (typeface == mMockedTypeFace); PowerMockito.verifyNoMoreInteractions(); }
@Test public void getTypeFaceFromAssetsFailTest() throws Exception { PowerMockito.mockStatic(Typeface.class); PowerMockito.mockStatic(Log.class); when(mMockContext.getAssets()).thenReturn(mMockedAssetManager); when(Typeface.createFromAsset(mMockedAssetManager, ASSET_PATH)).thenThrow(new RuntimeException()); when(Log.e(anyString(), anyString())).thenReturn(1); Typeface typeface = mTypeFaceProvider.getTypeFaceFromAssets(ASSET_PATH); PowerMockito.verifyStatic(times(2)); assert (typeface == null); PowerMockito.verifyNoMoreInteractions(); }