Java Code Examples for org.mockito.Mockito#verifyNoMoreInteractions()

The following examples show how to use org.mockito.Mockito#verifyNoMoreInteractions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TcpCollectorTest.java    From monsoon with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
@Test
public void connectFailed_withSocketException() throws Exception {
    Mockito.doThrow(new SocketException()).when(mockSocket).connect(Mockito.any());

    final TcpCollector.ConnectDatum result;
    try (TcpCollector tcpCollector = new TcpCollector(dstAddress, GROUP)) {
        result = tcpCollector.tryConnect(mockSocket);
    }

    assertThat(result.getResult(), equalTo(TcpCollector.ConnectResult.CONNECT_FAILED));
    Mockito.verify(mockSocket, times(1)).connect(Mockito.eq(dstAddress));
    Mockito.verifyNoMoreInteractions(mockSocket);
}
 
Example 2
Source File: CollectionServiceImplTest.java    From onboard with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetCollectionsByAttachTypeAndId() {

    List<Collection> collections = collectionServiceImpl.getCollectionsByAttachTypeAndId(ModuleHelper.userId,
            ModuleHelper.attachId, ModuleHelper.attachType);
    verify(mockedCollectionMapper, times(1)).selectByExample(Mockito.argThat(new ExampleMatcher<CollectionExample>() {

        @Override
        public boolean matches(BaseExample example) {
            return CriterionVerifier.verifyEqualTo(example, "userId", ModuleHelper.userId)
                    && CriterionVerifier.verifyEqualTo(example, "attachType", ModuleHelper.attachType)
                    && CriterionVerifier.verifyEqualTo(example, "attachId", ModuleHelper.attachId);
        }
    }));
    Mockito.verifyNoMoreInteractions(mockedCollectionMapper);
    runAsserts(collections, false);
}
 
Example 3
Source File: ObjectHeaderTest.java    From jhdf with MIT License 6 votes vote down vote up
@Test
void testLazyObjectHeader() throws ConcurrentException, IOException {
	FileChannel spyFc = Mockito.spy(fc);
	HdfFileChannel hdfFileChannel = new HdfFileChannel(spyFc, sb);
	LazyInitializer<ObjectHeader> lazyObjectHeader = ObjectHeader.lazyReadObjectHeader(hdfFileChannel, 10904); // int8
	// header
	// Creating the lazy object header should not touch the file
	Mockito.verifyNoInteractions(spyFc);

	// Get the actual header should cause the file to be read
	lazyObjectHeader.get();

	// Check the file was read
	verify(spyFc, Mockito.atLeastOnce()).read(any(ByteBuffer.class), anyLong());

	// Ensure nothing else was done to the file
	Mockito.verifyNoMoreInteractions(spyFc);
}
 
Example 4
Source File: ErrorBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testErrorChannelNotBoundByDefault() {
	ConfigurableApplicationContext applicationContext = SpringApplication.run(
			TestProcessor.class, "--server.port=0",
			"--spring.cloud.stream.default-binder=mock",
			"--spring.jmx.enabled=false");
	BinderFactory binderFactory = applicationContext.getBean(BinderFactory.class);

	Binder binder = binderFactory.getBinder(null, MessageChannel.class);

	Mockito.verify(binder).bindConsumer(eq("input"), isNull(),
			any(MessageChannel.class), any(ConsumerProperties.class));
	Mockito.verify(binder).bindProducer(eq("output"), any(MessageChannel.class),
			any(ProducerProperties.class));
	Mockito.verifyNoMoreInteractions(binder);
	applicationContext.close();
}
 
Example 5
Source File: JacksonModuleTest.java    From jsonschema-generator with Apache License 2.0 6 votes vote down vote up
@Test
@Parameters
public void testApplyToConfigBuilderWithEnumOptions(JacksonOption[] options) {
    new JacksonModule(options)
            .applyToConfigBuilder(this.configBuilder);

    this.verifyCommonConfigurations(true);

    Mockito.verify(this.configBuilder).forMethods();
    Mockito.verify(this.typesInGeneralConfigPart).withSubtypeResolver(Mockito.any());
    Mockito.verify(this.typesInGeneralConfigPart, Mockito.times(2)).withCustomDefinitionProvider(Mockito.any());
    Mockito.verify(this.fieldConfigPart).withTargetTypeOverridesResolver(Mockito.any());
    Mockito.verify(this.fieldConfigPart).withCustomDefinitionProvider(Mockito.any());
    Mockito.verify(this.methodConfigPart).withTargetTypeOverridesResolver(Mockito.any());
    Mockito.verify(this.methodConfigPart).withCustomDefinitionProvider(Mockito.any());

    Mockito.verifyNoMoreInteractions(this.configBuilder, this.fieldConfigPart, this.methodConfigPart, this.typesInGeneralConfigPart);
}
 
Example 6
Source File: EvalModelTest.java    From OpenModsLib with MIT License 6 votes vote down vote up
@Test
public void testDoubleApply() {
	EvaluatorFactory factory = new EvaluatorFactory();
	factory.appendStatement("param1 := 1.4");
	factory.appendStatement("clip(param1)");
	factory.appendStatement("clip(param2)");

	final ClipStub clipStub = new ClipStub();
	final IJointClip jointClipMock = clipStub.jointClipMock;

	final TRSRTransformation transform1 = TRSRTransformation.from(EnumFacing.NORTH);
	final TRSRTransformation transform2 = TRSRTransformation.from(EnumFacing.WEST);
	Mockito.when(jointClipMock.apply(1.4f)).thenReturn(transform1);
	Mockito.when(jointClipMock.apply(2.1f)).thenReturn(transform2);

	final TRSRTransformation result = factory.createEvaluator(clips("clip", clipStub)).evaluate(DUMMY_JOINT, ImmutableMap.of("param2", 2.1f));
	Assert.assertEquals(transform1.compose(transform2), result);

	Mockito.verify(jointClipMock).apply(1.4f);
	Mockito.verify(jointClipMock).apply(2.1f);
	Mockito.verifyNoMoreInteractions(jointClipMock);
}
 
Example 7
Source File: PopUpCoachMarkPresenterTest.java    From CoachMarks with Apache License 2.0 5 votes vote down vote up
@Test
public void setTypeFaceForCoachMarkTextNullTypefaceTest() {
    Mockito.when(mTypeFaceProvider.getTypeFaceFromAssets(Matchers.anyString())).thenReturn(null);

    mPopUpCoachMarkPresenter.setTypeFaceForCoachMarkText("fontFilePath");

    Mockito.verify(mTypeFaceProvider, Mockito.times(1)).getTypeFaceFromAssets("fontFilePath");
    Mockito.verify(mPopUpCoachMarkPresentation, Mockito.times(0))
            .setTypeFaceForPopUpText((Typeface) Matchers.anyObject());

    Mockito.verifyNoMoreInteractions(mPopUpCoachMarkPresentation);
}
 
Example 8
Source File: MongodbPanacheMockingTest.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Test
public void testPanacheRepositoryMocking() throws Throwable {
    Assertions.assertEquals(0, mockablePersonRepository.count());

    Mockito.when(mockablePersonRepository.count()).thenReturn(23l);
    Assertions.assertEquals(23, mockablePersonRepository.count());

    Mockito.when(mockablePersonRepository.count()).thenReturn(42l);
    Assertions.assertEquals(42, mockablePersonRepository.count());

    Mockito.when(mockablePersonRepository.count()).thenCallRealMethod();
    Assertions.assertEquals(0, mockablePersonRepository.count());

    Mockito.verify(mockablePersonRepository, Mockito.times(4)).count();

    PersonEntity p = new PersonEntity();
    Mockito.when(mockablePersonRepository.findById(12l)).thenReturn(p);
    Assertions.assertSame(p, mockablePersonRepository.findById(12l));
    Assertions.assertNull(mockablePersonRepository.findById(42l));

    Mockito.when(mockablePersonRepository.findById(12l)).thenThrow(new WebApplicationException());
    try {
        mockablePersonRepository.findById(12l);
        Assertions.fail();
    } catch (WebApplicationException x) {
    }

    Mockito.when(mockablePersonRepository.findOrdered()).thenReturn(Collections.emptyList());
    Assertions.assertTrue(mockablePersonRepository.findOrdered().isEmpty());

    Mockito.verify(mockablePersonRepository).findOrdered();
    Mockito.verify(mockablePersonRepository, Mockito.atLeastOnce()).findById(Mockito.any());
    Mockito.verifyNoMoreInteractions(mockablePersonRepository);
}
 
Example 9
Source File: FunnelTest.java    From mug with Apache License 2.0 5 votes vote down vote up
@Test public void batchInvokedWithAftereffectThatThrows() {
  MyUncheckedException exception = new MyUncheckedException();
  Funnel.Batch<Integer, String> toSpell = funnel.through(batch::send);
  Consumer<String> throwingEffect = s -> {throw exception;};
  toSpell.accept(1, throwingEffect);
  toSpell.accept(2);
  when(batch.send(asList(1, 2))).thenReturn(asList("one", "two"));
  assertThrows(MyUncheckedException.class, funnel::run);
  Mockito.verify(batch).send(asList(1, 2));
  Mockito.verifyNoMoreInteractions(batch);
}
 
Example 10
Source File: InterledgerPacketHandlerTest.java    From java-ilp-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testAbstractVoidHandler_QuoteLiquidityRequest() throws Exception {
  final InterledgerPayment interledgerPayment = mock(InterledgerPayment.class);
  final QuoteLiquidityRequest quoteLiquidityRequest = mock(QuoteLiquidityRequest.class);
  final QuoteLiquidityResponse quoteLiquidityResponse = mock(QuoteLiquidityResponse.class);

  new TestAbstractHandler().execute(quoteLiquidityRequest);

  Mockito.verifyNoMoreInteractions(interledgerPayment);
  Mockito.verify(quoteLiquidityRequest)
      .getDestinationAccount();
  Mockito.verifyNoMoreInteractions(quoteLiquidityResponse);
}
 
Example 11
Source File: JacksonModuleTest.java    From jsonschema-generator with Apache License 2.0 5 votes vote down vote up
@Test
public void testApplyToConfigBuilderWithSkipSubtypeLookupOption() {
    new JacksonModule(JacksonOption.SKIP_SUBTYPE_LOOKUP)
            .applyToConfigBuilder(this.configBuilder);

    this.verifyCommonConfigurations(true);

    Mockito.verify(this.configBuilder).forMethods();
    Mockito.verify(this.typesInGeneralConfigPart).withCustomDefinitionProvider(Mockito.any());
    Mockito.verify(this.fieldConfigPart).withCustomDefinitionProvider(Mockito.any());
    Mockito.verify(this.methodConfigPart).withCustomDefinitionProvider(Mockito.any());

    Mockito.verifyNoMoreInteractions(this.configBuilder, this.fieldConfigPart, this.methodConfigPart, this.typesInGeneralConfigPart);
}
 
Example 12
Source File: CheckCloudSdkTaskTest.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testCheckCloudSdkAction_callPluginsCoreChecksSkipJava()
    throws CloudSdkVersionFileException, CloudSdkNotFoundException, CloudSdkOutOfDateException,
        AppEngineJavaComponentsNotInstalledException {
  checkCloudSdkTask.setVersion("192.0.0");
  when(sdk.getVersion()).thenReturn(new CloudSdkVersion("192.0.0"));

  checkCloudSdkTask.checkCloudSdkAction();

  Mockito.verify(sdk).getVersion();
  Mockito.verify(sdk).validateCloudSdk();
  Mockito.verify(sdk, Mockito.never()).validateAppEngineJavaComponents();
  Mockito.verifyNoMoreInteractions(sdk);
}
 
Example 13
Source File: VariableDeserializationTypeValidationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldValidateContentTypeOnlyForArrayClass() {
  // given
  JavaType type = TypeFactory.defaultInstance().constructType(Integer[].class);
  setValidatorMockResult(true);

  // when
  variablesResourceSpy.validateType(type);

  // then
  Mockito.verify(validator).validate("java.lang.Integer");
  Mockito.verifyNoMoreInteractions(validator);
}
 
Example 14
Source File: StepServiceImplTest.java    From onboard with Apache License 2.0 5 votes vote down vote up
/**
 * @author Steven
 * Test that projectList is empty
 */
@Test
public void testGetCompletedStepsGroupByDateByUser_Test1() {
    TreeMap<Date, Map<Integer, List<Step>>> treeMap = 
            testedStepServiceImpl.getCompletedStepsGroupByDateByUser(
                    ModuleHelper.companyId, ModuleHelper.userId, new ArrayList<Integer>(), ModuleHelper.until, ModuleHelper.limit);
    
    Mockito.verifyNoMoreInteractions(mockStepMapper);
    
    assertEquals(0, treeMap.size());
}
 
Example 15
Source File: FileManagerTest.java    From PeerWasp with MIT License 5 votes vote down vote up
@Test
public void testUpdate() throws NoSessionException, NoPeerConnectionException {
	Mockito.stub(h2hFileManager.createUpdateProcess(any())).toReturn(process);
	ProcessHandle<Void> p = fileManager.update(file);
	assertNotNull(p);
	assertNotNull(p.getProcess());
	assertEquals(process, p.getProcess());

	Mockito.verify(h2hFileManager,  times(1)).createUpdateProcess(file.toFile());
	Mockito.verifyNoMoreInteractions(h2hFileManager);
}
 
Example 16
Source File: DeployExtensionTest.java    From app-gradle-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testToDeployConfiguration_allValuesSet() {
  DeployExtension testExtension = new DeployExtension(testProject);
  testExtension.setDeployTargetResolver(deployTargetResolver);

  testExtension.setBucket("test-bucket");
  testExtension.setGcloudMode("beta");
  testExtension.setImageUrl("test-img-url");
  testExtension.setProjectId("test-project-id");
  testExtension.setPromote(true);
  testExtension.setServer("test-server");
  testExtension.setStopPreviousVersion(true);
  testExtension.setVersion("test-version");

  List<Path> projects = ImmutableList.of(Paths.get("project1"), Paths.get("project2"));
  DeployConfiguration config = testExtension.toDeployConfiguration(projects);

  Assert.assertEquals(projects, config.getDeployables());
  Assert.assertEquals("test-bucket", config.getBucket());
  Assert.assertEquals("beta", config.getGcloudMode());
  Assert.assertEquals("test-img-url", config.getImageUrl());
  Assert.assertEquals("processed-project-id", config.getProjectId());
  Assert.assertEquals(Boolean.TRUE, config.getPromote());
  Assert.assertEquals("test-server", config.getServer());
  Assert.assertEquals(Boolean.TRUE, config.getStopPreviousVersion());
  Assert.assertEquals("processed-version", config.getVersion());

  Mockito.verify(deployTargetResolver).getProject("test-project-id");
  Mockito.verify(deployTargetResolver).getVersion("test-version");
  Mockito.verifyNoMoreInteractions(deployTargetResolver);
}
 
Example 17
Source File: JavaxValidationModuleTest.java    From jsonschema-generator with Apache License 2.0 5 votes vote down vote up
@Test
public void testApplyToConfigBuilderWithDefaultOptions() {
    new JavaxValidationModule().applyToConfigBuilder(this.configBuilder);

    this.verifyCommonConfigurations();

    Mockito.verifyNoMoreInteractions(this.configBuilder, this.fieldConfigPart, this.methodConfigPart);
}
 
Example 18
Source File: ProtoWriteSupportTest.java    From parquet-mr with Apache License 2.0 4 votes vote down vote up
@Test
public void testProto3MapIntMessageSpecsCompliant() throws Exception {
  RecordConsumer readConsumerMock =  Mockito.mock(RecordConsumer.class);
  Configuration conf = new Configuration();
  ProtoWriteSupport.setWriteSpecsCompliant(conf, true);
  ProtoWriteSupport instance = createReadConsumerInstance(TestProto3.MapIntMessage.class, readConsumerMock, conf);

  TestProto3.MapIntMessage.Builder msg = TestProto3.MapIntMessage.newBuilder();
  msg.putMapInt(123, 1);
  msg.putMapInt(234, 2);
  instance.write(msg.build());

  InOrder inOrder = Mockito.inOrder(readConsumerMock);

  inOrder.verify(readConsumerMock).startMessage();
  inOrder.verify(readConsumerMock).startField("mapInt", 0);
  inOrder.verify(readConsumerMock).startGroup();
  inOrder.verify(readConsumerMock).startField("key_value", 0);

  inOrder.verify(readConsumerMock).startGroup();
  inOrder.verify(readConsumerMock).startField("key", 0);
  inOrder.verify(readConsumerMock).addInteger(123);
  inOrder.verify(readConsumerMock).endField("key", 0);
  inOrder.verify(readConsumerMock).startField("value", 1);
  inOrder.verify(readConsumerMock).addInteger(1);
  inOrder.verify(readConsumerMock).endField("value", 1);
  inOrder.verify(readConsumerMock).endGroup();

  inOrder.verify(readConsumerMock).startGroup();
  inOrder.verify(readConsumerMock).startField("key", 0);
  inOrder.verify(readConsumerMock).addInteger(234);
  inOrder.verify(readConsumerMock).endField("key", 0);
  inOrder.verify(readConsumerMock).startField("value", 1);
  inOrder.verify(readConsumerMock).addInteger(2);
  inOrder.verify(readConsumerMock).endField("value", 1);
  inOrder.verify(readConsumerMock).endGroup();

  inOrder.verify(readConsumerMock).endField("key_value", 0);
  inOrder.verify(readConsumerMock).endGroup();
  inOrder.verify(readConsumerMock).endField("mapInt", 0);
  inOrder.verify(readConsumerMock).endMessage();
  Mockito.verifyNoMoreInteractions(readConsumerMock);
}
 
Example 19
Source File: InstancesMngrImplTest.java    From roboconf-platform with Apache License 2.0 4 votes vote down vote up
@Test
public void testRestoreInstances_rightHandler_vmRunning() throws Exception {

	// Prepare stuff
	INotificationMngr notificationMngr = Mockito.mock( INotificationMngr.class );
	IRandomMngr randomMngr = Mockito.mock( IRandomMngr.class );
	ITargetConfigurator targetConfigurator = Mockito.mock( ITargetConfigurator.class );

	IMessagingMngr messagingMngr = Mockito.mock( IMessagingMngr.class );
	Mockito.when( messagingMngr.getMessagingClient()).thenReturn( Mockito.mock( IDmClient.class ));

	ITargetsMngr targetsMngr = Mockito.mock( ITargetsMngr.class );
	Mockito.when( targetsMngr.findTargetProperties(
			Mockito.any( Application.class ),
			Mockito.anyString())).thenReturn( new TargetPropertiesImpl());

	IConfigurationMngr configurationMngr = new ConfigurationMngrImpl();
	configurationMngr.setWorkingDirectory( this.folder.newFolder());

	final TargetHandler targetHandlerArgument = Mockito.mock( TargetHandler.class );
	Mockito.when( targetHandlerArgument.getTargetId()).thenReturn( "some target id" );

	IInstancesMngr mngr = new InstancesMngrImpl( messagingMngr, notificationMngr, targetsMngr, randomMngr, targetConfigurator );
	((InstancesMngrImpl) mngr).setTargetHandlerResolver( new TestTargetResolver() {
		@Override
		public TargetHandler findTargetHandler( Map<String,String> targetProperties ) throws TargetException {
			return targetHandlerArgument;
		}
	});

	TestApplication app = new TestApplication();
	app.setDirectory( this.folder.newFolder());
	ManagedApplication ma = new ManagedApplication( app );

	// One scoped instance has a machine ID (considered as running somewhere)
	app.getMySqlVm().data.put( Instance.MACHINE_ID, "machine-id" );
	app.getMySqlVm().setStatus( InstanceStatus.DEPLOYING );

	// Try to restore instances
	Assert.assertEquals( InstanceStatus.DEPLOYING, app.getMySqlVm().getStatus());
	Mockito.when( targetHandlerArgument.isMachineRunning(
			Mockito.any( TargetHandlerParameters.class ),
			Mockito.eq( "machine-id" ))).thenReturn( true );

	mngr.restoreInstanceStates( ma, targetHandlerArgument );
	Assert.assertEquals( InstanceStatus.DEPLOYING, app.getMySqlVm().getStatus());

	// The handler's ID matched and the VM is running => a message was sent.
	Mockito.verify( targetsMngr ).findTargetProperties( Mockito.eq( app ), Mockito.anyString());
	Mockito.verify( targetsMngr ).findScriptForDm( Mockito.eq( app ), Mockito.eq( app.getMySqlVm()));
	Mockito.verify( targetsMngr ).unlockTarget( Mockito.eq( app ), Mockito.eq( app.getTomcatVm()));
	Mockito.verifyNoMoreInteractions( targetsMngr );

	Mockito.verify( targetHandlerArgument, Mockito.times( 1 )).isMachineRunning(
			Mockito.any( TargetHandlerParameters.class ),
			Mockito.eq( "machine-id" ));

	Mockito.verify( messagingMngr ).getMessagingClient();
	Mockito.verify( messagingMngr ).sendMessageDirectly(
			Mockito.eq( ma ),
			Mockito.eq( app.getMySqlVm() ),
			Mockito.any( MsgCmdSendInstances.class ));
	Mockito.verifyNoMoreInteractions( messagingMngr );

	// No notification was sent since there was no change on Tomcat instances
	Mockito.verifyZeroInteractions( notificationMngr );
	Mockito.verifyZeroInteractions( randomMngr );
	Mockito.verifyZeroInteractions( targetConfigurator );
}
 
Example 20
Source File: ProcessHandleTest.java    From PeerWasp with MIT License 4 votes vote down vote up
@Test
public void testExecuteAsync() throws InvalidProcessStateException, ProcessExecutionException {
	handle.executeAsync();
	Mockito.verify(process, Mockito.times(1)).executeAsync();
	Mockito.verifyNoMoreInteractions(process);
}