private void prepareWalletCreation(String input) { when(console.readLine(startsWith("Please enter the hex encoded private key"))) .thenReturn(input); when(console.readPassword(contains("password"))) .thenReturn(WALLET_PASSWORD, WALLET_PASSWORD); when(console.readLine(contains("Please enter a destination directory location"))) .thenReturn(tempDirPath); KeyImporter.main(console); verify(console).printf(contains("successfully created in")); } }
when(mockBlobStore.getBlobMeta(contains(expectedBlobKeyForArtifact))).thenReturn(new ReadableBlobMeta()); when(mockBlobStore.getBlobMeta(contains(expectedBlobKeyForArtifact2))).thenThrow(new KeyNotFoundException()); verify(mockBlobStore).getBlobMeta(contains(expectedBlobKeyForArtifact)); verify(mockBlobStore).getBlobMeta(contains(expectedBlobKeyForArtifact2)); verify(mockBlobStore, never()).deleteBlob(contains(expectedBlobKeyForArtifact)); verify(mockBlobStore, never()).deleteBlob(contains(expectedBlobKeyForArtifact2));
@Test public void uploadFilesWhichOneOfThemIsFailedToBeUploaded() throws Exception { File mockFile = createTemporaryDummyFile(); File mockFile2 = mock(File.class); when(mockFile2.getName()).thenReturn("dummy.jar"); when(mockFile2.isFile()).thenReturn(true); when(mockFile2.exists()).thenReturn(true); when(mockFile2.getPath()).thenThrow(new RuntimeException("just for test!")); when(mockFile2.toPath()).thenThrow(new RuntimeException("just for test!")); String mockFileFileNameWithoutExtension = Files.getNameWithoutExtension(mockFile.getName()); String mockFile2FileNameWithoutExtension = Files.getNameWithoutExtension(mockFile2.getName()); // we skip uploading first one since we want to test rollback, not upload when(mockBlobStore.getBlobMeta(contains(mockFileFileNameWithoutExtension))).thenReturn(new ReadableBlobMeta()); // we try uploading second one and it should be failed throwing RuntimeException when(mockBlobStore.getBlobMeta(contains(mockFile2FileNameWithoutExtension))).thenThrow(new KeyNotFoundException()); List<File> dependencies = Lists.newArrayList(mockFile, mockFile2); try { sut.uploadFiles(dependencies, true); fail("Should pass RuntimeException"); } catch (RuntimeException e) { // intended behavior } verify(mockBlobStore).getBlobMeta(contains(mockFileFileNameWithoutExtension)); verify(mockBlobStore).getBlobMeta(contains(mockFile2FileNameWithoutExtension)); verify(mockBlobStore).deleteBlob(contains(mockFileFileNameWithoutExtension)); verify(mockBlobStore, never()).deleteBlob(contains(mockFile2FileNameWithoutExtension)); }
@Test public void testWalletCreation() { when(console.readPassword(contains("password"))) .thenReturn(WALLET_PASSWORD, WALLET_PASSWORD); when(console.readLine(startsWith("Please enter a destination directory "))) .thenReturn(tempDirPath); WalletCreator.main(console); verify(console).printf(contains("successfully created in")); } }
@Test public void testInitMissingFilename() { when( meta.getSpecificationMethod() ).thenReturn( ObjectLocationSpecificationMethod.FILENAME ); assertFalse( baseStreamStep.init( meta, stepData ) ); verify( logChannel ).logError( contains( "Unable to load transformation " ), any( KettleException.class ) ); }
@Test public void testWalletUpdate() { when(console.readPassword(startsWith("Please enter your existing wallet file password"))) .thenReturn(WALLET_PASSWORD); when(console.readPassword(contains("password"))) .thenReturn(WALLET_PASSWORD, WALLET_PASSWORD); when(console.readLine(startsWith("Please enter a destination directory "))) .thenReturn(tempDirPath); when(console.readLine(startsWith("Would you like to delete"))) .thenReturn("N"); WalletUpdater.main(console, KeyImporterTest.class.getResource("/keyfiles/" + "UTC--2016-11-03T05-55-06.340672473Z--ef678007d18427e6022059dbc264f27507cd1ffc") .getFile()); verify(console).printf(contains("successfully created in")); } }
@Test public void shouldEnableAutoReadWhenAtLowWatermark() { BoltConnectionReadLimiter limiter = newLimiter( 1, 2 ); assertTrue( channel.config().isAutoRead() ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.drained( connection, Arrays.asList( job, job ) ); assertTrue( channel.config().isAutoRead() ); verify( log, times( 1 ) ).warn( contains( "disabled" ), eq( channel.remoteAddress() ), eq( 3 ) ); verify( log, times( 1 ) ).warn( contains( "enabled" ), eq( channel.remoteAddress() ), eq( 1 ) ); }
@Test public void shouldEnableAutoReadOnlyOnceWhenBelowLowWatermark() { BoltConnectionReadLimiter limiter = newLimiter( 1, 2 ); assertTrue( channel.config().isAutoRead() ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.drained( connection, Arrays.asList( job, job, job ) ); assertTrue( channel.config().isAutoRead() ); verify( log, times( 1 ) ).warn( contains( "disabled" ), eq( channel.remoteAddress() ), eq( 3 ) ); verify( log, times( 1 ) ).warn( contains( "enabled" ), eq( channel.remoteAddress() ), eq( 1 ) ); }
@Test public void shouldDisableAutoReadWhenAtHighWatermark() { BoltConnectionReadLimiter limiter = newLimiter( 1, 2 ); assertTrue( channel.config().isAutoRead() ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); assertFalse( channel.config().isAutoRead() ); verify( log ).warn( contains( "disabled" ), eq( channel.remoteAddress() ), eq( 3 ) ); }
@Test public void shouldDisableAutoReadOnlyOnceWhenAboveHighWatermark() { BoltConnectionReadLimiter limiter = newLimiter( 1, 2 ); assertTrue( channel.config().isAutoRead() ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); limiter.enqueued( connection, job ); assertFalse( channel.config().isAutoRead() ); verify( log, times( 1 ) ).warn( contains( "disabled" ), eq( channel.remoteAddress() ), eq( 3 ) ); }
@Override public Object match() { return Matchers.contains((String)getActualValue()); } }
@Test public void requestOneTimePayment_containsOfferPayPalCreditParam() throws JSONException { BraintreeFragment fragment = mMockFragmentBuilder.build(); PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").offerCredit(true)); ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class); verify(fragment.getHttpClient()).post(contains("/paypal_hermes/create_payment_resource"), dataCaptor.capture(), any(HttpResponseCallback.class)); JSONObject json = new JSONObject(dataCaptor.getValue()); assertTrue(json.getBoolean("offer_paypal_credit")); }
@Test public void addsInfoMessageWhenShuttingDownDueToInterrupt() throws Exception { // given doThrow(new InterruptedException()).when(socketConnector).call(); // when appender.start(); // then verify(appender, timeout(TIMEOUT)).addInfo(contains("shutting down")); }
@Test public void addsInfoMessageWhenSocketConnectionClosed() throws Exception { // given mockOneSuccessfulSocketConnection(); doThrow(new IOException()).when(objectWriterFactory).newAutoFlushingObjectWriter(any(OutputStream.class)); appender.start(); // when appender.append("some event"); // then verify(appender, timeout(TIMEOUT).atLeastOnce()).addInfo(contains("connection closed")); }
@Test public void createTransmissionTargetBeforeStart() { /* Given app center not configured. */ mockStatic(AppCenterLog.class); when(AppCenter.isConfigured()).thenReturn(false); /* When creating a target, it returns null. */ assertNull(Analytics.getTransmissionTarget("t1")); /* And prints an error. */ verifyStatic(); AppCenterLog.error(anyString(), contains("AppCenter is not configured")); }
@Test public void addsInfoMessageWhenSocketConnectionWasEstablished() throws Exception { // when mockOneSuccessfulSocketConnection(); appender.start(); // then verify(appender, timeout(TIMEOUT)).addInfo(contains("connection established")); }
@Test public void failsToStartWithUnresolvableRemoteHost() throws Exception { // given appender.setRemoteHost("NOT.A.VALID.REMOTE.HOST.NAME"); // when appender.start(); // then assertFalse(appender.isStarted()); verify(appender).addError(contains("unknown host")); }
@Test public void failsToStartWithoutValidRemoteHost() throws Exception { // given appender.setRemoteHost(null); // when appender.start(); // then assertFalse(appender.isStarted()); verify(appender).addError(contains("remote host")); }
@Test public void failsToStartWithNegativeQueueSize() throws Exception { // given appender.setQueueSize(-1); // when appender.start(); // then assertFalse(appender.isStarted()); verify(appender).addError(contains("Queue size must be greater than zero")); }
@Test public void clickSpinner() { CodeLabelExampleActivity activity = mActivityTestRule.launchActivity(null); activity.mSnackbarLogic = spy(new MockSnackbarLogic()); for (OrdinalLabel item : OrdinalLabel.values()) { onView(withId(R.id.spinner)).perform(click()); onData(is(item)).perform(click()); Resources res = activity.getResources(); verify(activity.mSnackbarLogic).make(any(View.class), contains(item.getLabel(res)), anyInt()); } } }