therore-spring-mockito

Therore Spring Mockito

License

License

Categories

Categories

Mockito Unit Testing Net
GroupId

GroupId

net.therore.spring.mockito
ArtifactId

ArtifactId

therore-spring-mockito
Last Version

Last Version

1.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

therore-spring-mockito
Therore Spring Mockito
Source Code Management

Source Code Management

http://github.com/alfredodiaz/therore-spring-mockito

Download therore-spring-mockito

How to add to project

<!-- https://jarcasting.com/artifacts/net.therore.spring.mockito/therore-spring-mockito/ -->
<dependency>
    <groupId>net.therore.spring.mockito</groupId>
    <artifactId>therore-spring-mockito</artifactId>
    <version>1.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/net.therore.spring.mockito/therore-spring-mockito/
implementation 'net.therore.spring.mockito:therore-spring-mockito:1.3.0'
// https://jarcasting.com/artifacts/net.therore.spring.mockito/therore-spring-mockito/
implementation ("net.therore.spring.mockito:therore-spring-mockito:1.3.0")
'net.therore.spring.mockito:therore-spring-mockito:jar:1.3.0'
<dependency org="net.therore.spring.mockito" name="therore-spring-mockito" rev="1.3.0">
  <artifact name="therore-spring-mockito" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.therore.spring.mockito', module='therore-spring-mockito', version='1.3.0')
)
libraryDependencies += "net.therore.spring.mockito" % "therore-spring-mockito" % "1.3.0"
[net.therore.spring.mockito/therore-spring-mockito "1.3.0"]

Dependencies

compile (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-all jar 1.10.19
ch.qos.logback : logback-classic jar 1.1.3

provided (4)

Group / Artifact Type Version
org.springframework : spring-core jar 4.2.4.RELEASE
org.springframework : spring-context jar 4.2.4.RELEASE
org.springframework : spring-beans jar 4.2.4.RELEASE
org.projectlombok : lombok jar 1.16.6

test (2)

Group / Artifact Type Version
org.springframework : spring-test jar 4.2.4.RELEASE
org.springframework.boot : spring-boot-autoconfigure jar 1.3.2.RELEASE

Project Modules

There are no modules declared in this project.

Spring Integration Tests With Mocks

This project is a fork of springmockedtests and uses the same method for injecting beans. Thank you a lot, Kresimir.

The goal is to have a mechanism to inject a mock in the Spring Context so it can replace the original one. I have used annotations in a bit different way.

Here's the test class:

@ComponentScan
@EnableMockedBean
@EnableAutoConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MySampleServiceTest.class)
public class MySampleServiceTest {

    @MockedBean
    private HelloWorldService helloWorldService;

    @Test
    public void helloWorldIsCalledOnlyOnce() throws Exception {

        // WHEN I launch SampleSimpleApplication
        SampleSimpleApplication.main(new String[0]);

        // THEN HelloWorldService is called only once
        verify(helloWorldService,times(1)).getHelloMessage();
    }

}

The class have to be annotated with @EnableMockedBeanand every "mocked bean" with @MockedBean to work properly.

In this example a mock of type HelloWorldService is injected in the context and is autowired to the field helloWorldService.

Include the following dependency in your pom file in order to use it.

<dependency>
    <groupId>net.therore.spring.mockito</groupId>
    <artifactId>therore-spring-mockito</artifactId>
</dependency>

Versions

Version
1.3.0
1.2.0
1.1.0
1.0