Java Code Examples for org.mockito.BDDMockito#mock()

The following examples show how to use org.mockito.BDDMockito#mock() . 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: SpringMetaReleaseAcceptanceTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Bean
PostReleaseActions myPostReleaseActions() {
	return BDDMockito
			.mock(PostReleaseActions.class,
					invocation -> invocation.getMethod().getReturnType()
							.equals(ExecutionResult.class)
									? ExecutionResult.success() : null);
}
 
Example 2
Source File: SpringSingleProjectAcceptanceTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Bean
SaganClient testSaganClient() {
	SaganClient saganClient = BDDMockito.mock(SaganClient.class);
	BDDMockito.given(saganClient.getProject(anyString()))
			.willReturn(newProject());
	return saganClient;
}
 
Example 3
Source File: TraceExchangeFilterFunctionHttpClientResponseTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_0_when_invalid_status_code_is_returned() {
	ClientResponse clientResponse = BDDMockito.mock(ClientResponse.class);
	BDDMockito.given(clientResponse.rawStatusCode()).willReturn(-1);
	ClientResponseWrapper response = new ClientResponseWrapper(clientResponse);

	Integer statusCode = response.statusCode();

	BDDAssertions.then(statusCode).isZero();
}
 
Example 4
Source File: ExecutorBeanPostProcessorTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_do_nothing_when_bean_is_already_traceable_executor()
		throws Exception {
	TraceableExecutorService service = BDDMockito
			.mock(TraceableExecutorService.class);

	Object o = new ExecutorBeanPostProcessor(this.beanFactory)
			.postProcessAfterInitialization(service, "foo");

	then(o).isSameAs(service);
}
 
Example 5
Source File: ExecutorBeanPostProcessorTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_do_nothing_when_bean_is_already_traceable_scheduled_executor()
		throws Exception {
	TraceableScheduledExecutorService service = BDDMockito
			.mock(TraceableScheduledExecutorService.class);

	Object o = new ExecutorBeanPostProcessor(this.beanFactory)
			.postProcessAfterInitialization(service, "foo");

	then(o).isSameAs(service);
}
 
Example 6
Source File: ExecutorBeanPostProcessorTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_do_nothing_when_bean_is_already_lazy_thread_pool_task_executor()
		throws Exception {
	LazyTraceThreadPoolTaskExecutor service = BDDMockito
			.mock(LazyTraceThreadPoolTaskExecutor.class);

	Object o = new ExecutorBeanPostProcessor(this.beanFactory)
			.postProcessAfterInitialization(service, "foo");

	then(o).isSameAs(service);
}
 
Example 7
Source File: ProjectPomUpdaterTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void should_skip_any_steps_if_there_is_no_pom_xml() {
	ReleaserProperties properties = SpringCloudReleaserProperties.get();
	ProjectGitHandler handler = BDDMockito.mock(ProjectGitHandler.class);
	ProjectPomUpdater updater = new ProjectPomUpdater(properties,
			Collections.emptyList());

	updater.updateProjectFromReleaseTrain(new File("target"), new Projects(),
			new ProjectVersion("foo", "1.0.0.RELEASE"), false);

	BDDMockito.then(handler).shouldHaveZeroInteractions();
}
 
Example 8
Source File: RestartSiteProjectPostReleaseTaskTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private ProjectToRun nonReactorCoreProject() {
	return new ProjectToRun(null,
			new ProjectsFromBom(new Projects(), new ProjectVersion("foo", "1.0.0")),
			new ProjectVersion("foo", "1.0.0"), new ReleaserProperties(),
			BDDMockito.mock(Options.class)) {
		@Override
		public String name() {
			return "whatever";
		}
	};
}
 
Example 9
Source File: ExecutorBeanPostProcessorTests.java    From spring-cloud-sleuth with Apache License 2.0 5 votes vote down vote up
@Test
public void should_do_nothing_when_bean_is_already_lazy_trace_async_task_executor()
		throws Exception {
	LazyTraceAsyncTaskExecutor service = BDDMockito
			.mock(LazyTraceAsyncTaskExecutor.class);

	Object o = new ExecutorBeanPostProcessor(this.beanFactory)
			.postProcessAfterInitialization(service, "foo");

	then(o).isSameAs(service);
}
 
Example 10
Source File: GithubIssuesTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_do_anything_for_non_release_train_version() {
	Github github = BDDMockito.mock(Github.class);
	GithubIssues issues = new GithubIssues(Collections.emptyList());

	issues.fileIssueInSpringGuides(
			new Projects(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"),
					new ProjectVersion("spring-cloud-build", "2.0.0.BUILD-SNAPSHOT")),
			new ProjectVersion("sc-release", "Edgware.BUILD-SNAPSHOT"));

	BDDMockito.then(github).shouldHaveZeroInteractions();
}
 
Example 11
Source File: GithubIssuesTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_do_anything_if_not_applicable() {
	Github github = BDDMockito.mock(Github.class);
	GithubIssues issues = new GithubIssues(Collections.emptyList());

	issues.fileIssueInSpringGuides(
			new Projects(new ProjectVersion("foo", "1.0.0.RELEASE"),
					new ProjectVersion("bar", "2.0.0.RELEASE"),
					new ProjectVersion("baz", "3.0.0.RELEASE")),
			new ProjectVersion("sc-release", "Edgware.RELEASE"));

	BDDMockito.then(github).shouldHaveZeroInteractions();
}
 
Example 12
Source File: GithubIssuesTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_do_anything_for_non_release_train_version_when_updating_startspringio()
		throws IOException {
	setupStartSpringIo();
	Github github = BDDMockito.mock(Github.class);
	GithubIssues issues = new GithubIssues(Collections.emptyList());

	issues.fileIssueInStartSpringIo(
			new Projects(new ProjectVersion("foo", "1.0.0.BUILD-SNAPSHOT"),
					new ProjectVersion("spring-cloud-build", "2.0.0.RELEASE")),
			new ProjectVersion("sc-release", "Edgware.BUILD-SNAPSHOT"));

	BDDMockito.then(github).shouldHaveZeroInteractions();
}
 
Example 13
Source File: GithubIssuesTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void should_not_do_anything_if_not_applicable_when_updating_startspringio()
		throws IOException {
	setupStartSpringIo();
	Github github = BDDMockito.mock(Github.class);
	GithubIssues issues = new GithubIssues(Collections.emptyList());

	issues.fileIssueInStartSpringIo(
			new Projects(new ProjectVersion("foo", "1.0.0.RELEASE"),
					new ProjectVersion("bar", "2.0.0.RELEASE"),
					new ProjectVersion("baz", "3.0.0.RELEASE")),
			new ProjectVersion("sc-release", "Edgware.RELEASE"));

	BDDMockito.then(github).shouldHaveZeroInteractions();
}
 
Example 14
Source File: PostReleaseActionsTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void should_do_nothing_when_guides_are_turned_off() {
	this.properties.getGit().setUpdateSpringGuides(false);
	VersionsFetcher versionsFetcher = BDDMockito.mock(VersionsFetcher.class);
	PostReleaseActions actions = new PostReleaseActions(this.projectGitHandler,
			this.updater, this.gradleUpdater, this.commandExecutor, this.properties,
			versionsFetcher, releaserPropertiesUpdater);

	actions.deployGuides(Collections.emptyList());

	BDDAssertions.then(this.cloned).isNull();
	BDDMockito.then(versionsFetcher).shouldHaveZeroInteractions();
}
 
Example 15
Source File: TestGeneratorTests.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Test
public void should_not_throw_exception_when_in_progress_contracts_found_but_the_fail_on_in_progress_switch_is_off() {
	// given:
	ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties();
	properties.setFailOnInProgress(false);
	properties.setContractsDslDir(new File("."));
	SingleTestGenerator singleTestGenerator = BDDMockito
			.mock(SingleTestGenerator.class);
	FileSaver fileSaver = BDDMockito.mock(FileSaver.class);
	// and:
	MultiValueMap<Path, ContractMetadata> multimap = CollectionUtils
			.toMultiValueMap(new LinkedHashMap<>());
	Path path = new File(".").toPath();
	multimap.add(path,
			new ContractMetadata(path, false, 0, null, Contract.make(it -> {
				it.inProgress();
				it.request(r -> {
					r.method(r.GET());
					r.url("/foo");
				});
				it.response(r -> {
					r.status(r.OK());
				});
			})));
	ContractFileScanner scanner = new ContractFileScanner(null, null, null) {
		@Override
		public MultiValueMap<Path, ContractMetadata> findContractsRecursively() {
			return multimap;
		}
	};
	// and:
	TestGenerator testGenerator = new TestGenerator(properties, singleTestGenerator,
			fileSaver, scanner) {
		@Override
		Set<Map.Entry<Path, List<ContractMetadata>>> processAllNotInProgress(
				MultiValueMap<Path, ContractMetadata> contracts,
				String basePackageName) {
			return null;
		}
	};

	// when:
	testGenerator.generateTestClasses("com.example");

	// then: noExceptionThrown()
}
 
Example 16
Source File: TestGeneratorTests.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Test
public void should_throw_exception_when_in_progress_contracts_found() {
	// given:
	ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties();
	properties.setFailOnInProgress(true);
	properties.setContractsDslDir(new File("."));
	SingleTestGenerator singleTestGenerator = BDDMockito
			.mock(SingleTestGenerator.class);
	FileSaver fileSaver = BDDMockito.mock(FileSaver.class);
	// and:
	MultiValueMap<Path, ContractMetadata> multimap = CollectionUtils
			.toMultiValueMap(new LinkedHashMap<>());
	Path path = new File(".").toPath();
	multimap.add(path,
			new ContractMetadata(path, false, 0, null, Contract.make(it -> {
				it.inProgress();
				it.request(r -> {
					r.method(r.GET());
					r.url("/foo");
				});
				it.response(r -> {
					r.status(r.OK());
				});
			})));
	ContractFileScanner scanner = new ContractFileScanner(null, null, null) {
		@Override
		public MultiValueMap<Path, ContractMetadata> findContractsRecursively() {
			return multimap;
		}
	};
	// and:
	TestGenerator testGenerator = new TestGenerator(properties, singleTestGenerator,
			fileSaver, scanner);

	// then:
	BDDAssertions.thenThrownBy(() -> {
		// when:
		testGenerator.generateTestClasses("com.example");
	}).isInstanceOf(IllegalStateException.class)
			.hasMessageContaining("In progress contracts found in");
}
 
Example 17
Source File: SpringBatchFlowRunnerTests.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
@Bean
ProjectsToRunFactory projectsToRunFactory() {
	return BDDMockito.mock(ProjectsToRunFactory.class);
}
 
Example 18
Source File: SleuthTestAutoConfiguration.java    From spring-cloud-sleuth with Apache License 2.0 4 votes vote down vote up
@Bean
@ConditionalOnProperty(value = "test.mongo.mock.enabled", matchIfMissing = true)
MongoClient mongoClient() {
	return BDDMockito.mock(MongoClient.class);
}
 
Example 19
Source File: CfTestConfiguration.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
@Bean
CloudFoundryOperations mockCloudFoundryOperations() {
	return BDDMockito.mock(CloudFoundryOperations.class);
}
 
Example 20
Source File: SpringSingleProjectAcceptanceTests.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
@Bean
PostReleaseActions myPostReleaseActions() {
	return BDDMockito.mock(PostReleaseActions.class);
}