ViewHelper { public Activity getActivity(final Context viewContext) { Context context = viewContext; while (!(context instanceof Activity) && context instanceof ContextWrapper) { context = ((ContextWrapper) context).getBaseContext(); } if (!(context instanceof Activity)) { throw new IllegalStateException( "Expected an activity context, got " + context.getClass().getSimpleName()); } return (Activity) context; } private  ViewHelper(); static ViewHelper getInstance(); Activity getActivity(final Context viewContext);  }
@Test public void testGetActivity() throws Exception { Activity spy = spy(Activity.class); Activity result = ViewHelper.getInstance().getActivity(spy); Assert.assertEquals(result, spy); }