@Before public void setup() { Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT_V2 = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT_V2); ShadowSettings.setTestURL(url.toString()); TestResponsesUT.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
@Before public void setUp() throws Exception { QMail.setDebug(true); ShadowLog.stream = System.out; ShadowSQLiteConnection.reset(); account = getNewAccount(); StorageManager storageManager = StorageManager.getInstance(RuntimeEnvironment.application); databaseFile = storageManager.getDatabase(account.getUuid(), account.getLocalStorageProviderId()); Assert.assertTrue(databaseFile.getParentFile().isDirectory() || databaseFile.getParentFile().mkdir()); attachmentDir = StorageManager.getInstance(RuntimeEnvironment.application).getAttachmentDirectory( account.getUuid(), account.getLocalStorageProviderId()); Assert.assertTrue(attachmentDir.isDirectory() || attachmentDir.mkdir()); }
@Before public void setUp() throws Exception { connectivityManager = mock(ConnectivityManager.class); oAuth2TokenProvider = createOAuth2TokenProvider(); socketFactory = TestTrustedSocketFactory.newInstance(); settings = new SimpleImapSettings(); settings.setUsername(USERNAME); settings.setPassword(PASSWORD); if (DEBUGGING) { ShadowLog.stream = System.out; K9MailLib.setDebug(true); K9MailLib.setDebugSensitive(true); } }
private static void assertExceptionLogged(int logType, String message, String exceptionClassname, String tag, int index) { List<LogItem> logs = ShadowLog.getLogs(); assertThat(logs).hasSize(index + 1); LogItem log = logs.get(index); assertThat(log.type).isEqualTo(logType); assertThat(log.tag).isEqualTo(tag != null ? tag : "TimberTest"); if (message != null) { assertThat(log.msg).startsWith(message); } assertThat(log.msg).contains(exceptionClassname); // We use a low-level primitive that Robolectric doesn't populate. assertThat(log.throwable).isNull(); }
@Before public void setUp() throws Exception { K9.DEBUG = true; ShadowLog.stream = System.out; ShadowSQLiteConnection.reset(); account = getNewAccount(); StorageManager storageManager = StorageManager.getInstance(RuntimeEnvironment.application); databaseFile = storageManager.getDatabase(account.getUuid(), account.getLocalStorageProviderId()); Assert.assertTrue(databaseFile.getParentFile().isDirectory() || databaseFile.getParentFile().mkdir()); attachmentDir = StorageManager.getInstance(RuntimeEnvironment.application).getAttachmentDirectory( account.getUuid(), account.getLocalStorageProviderId()); Assert.assertTrue(attachmentDir.isDirectory() || attachmentDir.mkdir()); }
@Before public void setUp() throws IOException { // Output logs emitted during tests so they may be accessed ShadowLog.stream = System.out; activity = Robolectric.setupActivity(ImportExportActivity.class); db = new DBHelper(activity); imageDir = activity.getExternalFilesDir(Environment.DIRECTORY_PICTURES); assertNotNull(imageDir); boolean result; if(imageDir.exists() == false) { result = imageDir.mkdirs(); assertTrue(result); } missingReceipt = new File(imageDir, "missing"); orphanReceipt = new File(imageDir, "orphan"); result = orphanReceipt.createNewFile(); assertTrue(result); }
@Before public void setupDagger() { DaggerApplicationComponentTest.builder() .applicationContextModuleTest(new ApplicationContextModuleTest()) .repositoryModuleTest(new RepositoryModuleTest(false)) .build().inject(this); //activity = Robolectric.setupActivity(MainActivity.class); activity = Robolectric.buildActivity(MainActivity.class) .create() .start() .resume() .visible() .get(); tradeAdapter = mock(TradeRecyclerViewAdapter.class); fab = (FloatingActionButton) activity.findViewById(R.id.fab); rvTrades = (RealmRecyclerView) activity.findViewById(R.id.list_trades); //This is for printing log messages in console ShadowLog.stream = System.out; }
@Before public void setUp() throws Exception { ShadowLog.stream = System.out; mockWebServer = new MockWebServer(); mockWebServer.start(9999); baseRetryHandler = BaseRetryHandler_.getInstance_(RuntimeEnvironment.application); connectivityAwareUrlClient = ConnectivityAwareUrlClient_.getInstance_(RuntimeEnvironment.application); connectivityAwareUrlClient.setWrappedClient(new OkClient(new OkHttpClient())); connectivityAwareUrlClient.setRetryHandler(baseRetryHandler); RestAdapter restAdapter = new RestAdapter.Builder() .setClient(connectivityAwareUrlClient) .setLogLevel(RestAdapter.LogLevel.FULL) .setEndpoint(mockWebServer.getUrl("/").toString()).build(); sodaService = restAdapter.create(SodaService.class); }
public static void copyDataSet(String filename) throws IllegalArgumentException{ // /test/resources/databses/<filename> String targetPath = TestHelper.getDatabasePath(); ShadowLog.stream = System.out; File dbFile = new File(TestHelper.getTestResourcePath().concat("databases/" + filename)); if (!dbFile.exists()) { System.out.print("File does not exist"); } File targetDir = new File(targetPath); if(!targetDir.exists()) { targetDir.mkdirs(); } File targetFile = new File(targetPath + "AluShareDataBase.db"); if (targetFile.exists()) { targetFile.delete(); } try { TestHelper.copyFileUsingStream(dbFile,targetFile); } catch (IOException e) { System.out.println("File copy failed"); } }
@Test public void loadPositions_withNoConnection_shouldLogMoPubErrorCodeNoConnection_shouldCallFailureHandler() { MoPubLog.setSdkHandlerLevel(Level.ALL); when(mockContext.checkCallingOrSelfPermission(anyString())) .thenReturn(PackageManager.PERMISSION_DENIED); when(spyActivity.getApplicationContext()).thenReturn(mockContext); // Reinit the subject so we get our mocked context. subject = new ServerPositioningSource(spyActivity); // Simulate failure after max time. subject.setMaximumRetryTimeMilliseconds(999); subject.loadPositions("test_ad_unit", mockPositioningListener); verify(mockRequestQueue).add(positionRequestCaptor.capture()); positionRequestCaptor.getValue().deliverError(new NoConnectionError()); verify(mockPositioningListener).onFailed(); final List<ShadowLog.LogItem> allLogMessages = ShadowLog.getLogs(); final ShadowLog.LogItem latestLogMessage = allLogMessages.get(allLogMessages.size() - 2); // All log messages end with a newline character. assertThat(latestLogMessage.msg.trim()).isEqualTo(MoPubErrorCode.NO_CONNECTION.toString()); }
@Test public void displayWarningForMissingActivities_withOneMissingActivity_shouldLogOnlyThatOne() throws Exception { Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MraidActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MraidVideoPlayerActivity.class), mockResolveInfo); // Here, we leave out MoPubBrowser on purpose ShadowLog.setupLogging(); ManifestUtils.displayWarningForMissingActivities(context, requiredWebViewSdkActivities); assertLogIncludes("com.mopub.common.MoPubBrowser"); assertLogDoesntInclude( "com.mopub.mobileads.MoPubActivity", "com.mopub.mobileads.MraidActivity", "com.mopub.mobileads.MraidVideoPlayerActivity" ); }
@Test public void displayWarningForMissingActivities_withAllMissingActivities_shouldLogMessage() throws Exception { setDebugMode(true); ShadowLog.setupLogging(); ManifestUtils.displayWarningForMissingActivities(context, requiredWebViewSdkActivities); final List<ShadowLog.LogItem> logs = ShadowLog.getLogs(); assertLogIncludes( "com.mopub.mobileads.MoPubActivity", "com.mopub.mobileads.MraidActivity", "com.mopub.mobileads.MraidVideoPlayerActivity", "com.mopub.common.MoPubBrowser" ); }
@SuppressWarnings("unchecked") @TargetApi(13) @Test public void displayWarningForMisconfiguredActivities_withAllActivitiesConfigured_shouldNotLogOrShowToast() throws Exception { ManifestUtils.FlagCheckUtil mockActivitiyConfigCheck = mock(ManifestUtils.FlagCheckUtil.class); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_KEYBOARD_HIDDEN))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_ORIENTATION))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_SCREEN_SIZE))).thenReturn(true); ManifestUtils.setFlagCheckUtil(mockActivitiyConfigCheck); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MraidActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MraidVideoPlayerActivity.class), mockResolveInfo); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubBrowser.class), mockResolveInfo); ShadowLog.setupLogging(); setDebugMode(true); ManifestUtils.displayWarningForMisconfiguredActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNull(); assertThat(ShadowLog.getLogs()).isEmpty(); }
@SuppressWarnings("unchecked") @TargetApi(13) @Test public void displayWarningForMisconfiguredActivities_withOneMisconfiguredActivity_withMissingAllConfigChangesValues_shouldLogAllConfigChangesValues() throws Exception { ManifestUtils.FlagCheckUtil mockActivitiyConfigCheck = mock(ManifestUtils.FlagCheckUtil.class); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_KEYBOARD_HIDDEN))).thenReturn(false); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_ORIENTATION))).thenReturn(false); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_SCREEN_SIZE))).thenReturn(false); ManifestUtils.setFlagCheckUtil(mockActivitiyConfigCheck); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); ShadowLog.setupLogging(); ManifestUtils.displayWarningForMisconfiguredActivities(context, requiredWebViewSdkActivities); assertLogIncludes("The android:configChanges param for activity " + MoPubActivity.class.getName() + " must include keyboardHidden."); assertLogIncludes("The android:configChanges param for activity " + MoPubActivity.class.getName() + " must include orientation."); assertLogIncludes("The android:configChanges param for activity " + MoPubActivity.class.getName() + " must include screenSize."); }
@SuppressWarnings("unchecked") @Config(reportSdk = Build.VERSION_CODES.HONEYCOMB_MR1) @TargetApi(13) @Test public void displayWarningForMisconfiguredActivities_withMissingScreenSize_withApiLessThan13_shouldNotLogOrShowToast() throws Exception { ManifestUtils.FlagCheckUtil mockActivitiyConfigCheck = mock(ManifestUtils.FlagCheckUtil.class); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_KEYBOARD_HIDDEN))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_ORIENTATION))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_SCREEN_SIZE))).thenReturn(false); ManifestUtils.setFlagCheckUtil(mockActivitiyConfigCheck); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); ShadowLog.setupLogging(); setDebugMode(true); ManifestUtils.displayWarningForMisconfiguredActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNull(); assertThat(ShadowLog.getLogs()).isEmpty(); }
@SuppressWarnings("unchecked") @TargetApi(13) @Test public void displayWarningForMisconfiguredActivities_withMissingScreenSize_withTargetApiLessThan13_shouldNotLogOrShowToast() throws Exception { // Set target API to < 13 ApplicationInfo applicationInfo = context.getApplicationInfo(); applicationInfo.targetSdkVersion = Build.VERSION_CODES.HONEYCOMB_MR1; when(context.getApplicationInfo()).thenReturn(applicationInfo); ManifestUtils.FlagCheckUtil mockActivitiyConfigCheck = mock(ManifestUtils.FlagCheckUtil.class); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_KEYBOARD_HIDDEN))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_ORIENTATION))).thenReturn(true); when(mockActivitiyConfigCheck.hasFlag(any(Class.class), anyInt(), eq(ActivityInfo.CONFIG_SCREEN_SIZE))).thenReturn(false); ManifestUtils.setFlagCheckUtil(mockActivitiyConfigCheck); Robolectric.packageManager.addResolveInfoForIntent(new Intent(context, MoPubActivity.class), mockResolveInfo); ShadowLog.setupLogging(); setDebugMode(true); ManifestUtils.displayWarningForMisconfiguredActivities(context, requiredWebViewSdkActivities); assertThat(ShadowToast.getLatestToast()).isNull(); assertThat(ShadowLog.getLogs()).isEmpty(); }
@Before public void setup() throws IOException { ShadowLog.stream = System.out; System.out.println(); System.out .println("*******************************************************"); System.out.println("***** TEST: " + name.getMethodName() + " *****"); System.out .println("*******************************************************"); System.out.println(); parser = new VASTProcessor(new myMediaPicker()); }
@Before public void setup() { // Print out everything from logcat to the console instead ShadowLog.stream = System.out; // Setup variables mContext = RuntimeEnvironment.application; mEditText = new ContactEditText(mContext); // Update the owner's contact in TextManager ShadowTextManager shadowTextManager = (ShadowTextManager) ShadowExtractor.extract(TextManager.getInstance(mContext)); shadowTextManager.setSelf(ME); shadowTextManager.addContact(NAMELESS); shadowTextManager.addContact(ALICE); shadowTextManager.addContact(BOB); shadowTextManager.addContact(CHARLIE); shadowTextManager.addContact(DEBRA); }
@Before public void setup() { Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT_V2 = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT_V2); ShadowSettings.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
@Before public void setUp() throws MessagingException { ShadowLog.stream = System.out; MockitoAnnotations.initMocks(this); appContext = ShadowApplication.getInstance().getApplicationContext(); controller = new MessagingController(appContext, notificationController, contacts, transportProvider); configureAccount(); configureLocalStore(); }
@Before public void setUp() throws MessagingException { ShadowLog.stream = System.out; Application application = RuntimeEnvironment.application; QMail.app = application; GlobalsHelper.setContext(application); StorageManager.getInstance(application); storeSchemaDefinition = createStoreSchemaDefinition(); }
@Before public void setup() { ShadowLog.stream = System.out; mActivity = Robolectric.buildActivity(Activity.class).create().get(); mRecyclerView = new RecyclerView(mActivity); mLayoutManager = new VirtualLayoutManager(mActivity); }
@Test public void log() { LogStrategy logStrategy = new LogcatLogStrategy(); logStrategy.log(DEBUG, "tag", "message"); List<ShadowLog.LogItem> logItems = ShadowLog.getLogs(); assertThat(logItems.get(0).type).isEqualTo(DEBUG); assertThat(logItems.get(0).msg).isEqualTo("message"); assertThat(logItems.get(0).tag).isEqualTo("tag"); }
/** Tests that the computed call origin is the correct one. */ @Test public void callOriginTest() { Log.d("Foo", "Bar"); List<ShadowLog.LogItem> logs = ShadowLog.getLogs(); assertEquals("Only one log should be written", 1, logs.size()); assertTrue("The origin of the log message (" + logs.get(0).msg + ") looks wrong.", logs.get(0).msg.matches("\\[LogTest.java:\\d+\\].*")); }
/** Tests that exceptions provided to the log functions are properly recognized and printed. */ @Test public void exceptionLoggingTest() { Throwable t = new Throwable() { @Override public String toString() { return "MyThrowable"; } }; Throwable t2 = new Throwable() { @Override public String toString() { return "MyOtherThrowable"; } }; List<ShadowLog.LogItem> logs = ShadowLog.getLogs(); // The throwable gets printed out Log.i("Foo", "Bar", t); assertEquals(t, logs.get(logs.size() - 1).throwable); assertEquals("Bar", logs.get(logs.size() - 1).msg); // The throwable can be both added to the message itself and printed out Log.i("Foo", "Bar %s", t); assertEquals(t, logs.get(logs.size() - 1).throwable); assertEquals("Bar MyThrowable", logs.get(logs.size() - 1).msg); // Non throwable are properly identified Log.i("Foo", "Bar %s", t, "Baz"); assertNull(logs.get(logs.size() - 1).throwable); assertEquals("Bar MyThrowable", logs.get(logs.size() - 1).msg); // The last throwable is the one used that is going to be printed out Log.i("Foo", "Bar %s %s", t, t2); assertEquals(t2, logs.get(logs.size() - 1).throwable); assertEquals("Bar MyThrowable MyOtherThrowable", logs.get(logs.size() - 1).msg); }
@Before public void setUp() { ShadowLog.stream = System.out; clientEvents = mock(AppRTCClient.SignalingEvents.class); serverEvents = mock(AppRTCClient.SignalingEvents.class); client = new DirectRTCClient(clientEvents); server = new DirectRTCClient(serverEvents); }
@Before public void setUp() { ShadowLog.stream = System.out; MockitoAnnotations.initMocks(this); executor = Executors.newSingleThreadExecutor(); }
@Before public void setUp() { // Output logs emitted during tests so they may be accessed ShadowLog.stream = System.out; Activity activity = Robolectric.setupActivity(PropertiesListActivity.class); db = new DBHelper(activity); }
@Before public void setUp() { // Output logs emitted during tests so they may be accessed ShadowLog.stream = System.out; db = new DBHelper(RuntimeEnvironment.application); }
@Before public void setUp() { // Output logs emitted during tests so they may be accessed ShadowLog.stream = System.out; db = new DBHelper(RuntimeEnvironment.application); prefs = RuntimeEnvironment.application.getSharedPreferences("protect.rentalcalc", Context.MODE_PRIVATE); // Assume that this is not the first launch prefs.edit().putBoolean("firstrun", false).commit(); }