Spock-HK2

Spock extension which helps writing integration tests in your HK2-based application with explicit binders.

License

License

Categories

Categories

Spock Application Testing & Monitoring HK2 Application Layer Libs Dependency Injection
GroupId

GroupId

com.github.pbetkier
ArtifactId

ArtifactId

spock-hk2
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

Spock-HK2
Spock extension which helps writing integration tests in your HK2-based application with explicit binders.
Project URL

Project URL

https://github.com/pbetkier/spock-hk2
Source Code Management

Source Code Management

https://github.com/pbetkier/spock-hk2

Download spock-hk2

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.pbetkier/spock-hk2/ -->
<dependency>
    <groupId>com.github.pbetkier</groupId>
    <artifactId>spock-hk2</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.pbetkier/spock-hk2/
implementation 'com.github.pbetkier:spock-hk2:0.1.0'
// https://jarcasting.com/artifacts/com.github.pbetkier/spock-hk2/
implementation ("com.github.pbetkier:spock-hk2:0.1.0")
'com.github.pbetkier:spock-hk2:jar:0.1.0'
<dependency org="com.github.pbetkier" name="spock-hk2" rev="0.1.0">
  <artifact name="spock-hk2" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.pbetkier', module='spock-hk2', version='0.1.0')
)
libraryDependencies += "com.github.pbetkier" % "spock-hk2" % "0.1.0"
[com.github.pbetkier/spock-hk2 "0.1.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.spockframework : spock-core jar 0.7-groovy-2.0

Project Modules

There are no modules declared in this project.

Spock-HK2 Build Status

Spock extension which helps writing integration tests in your HK2-based application with explicit binders.

Installation

Add a dependency on Spock-HK2 from Maven Central, e.g. in Gradle build file:

testCompile 'com.github.pbetkier:spock-hk2:0.1.0'

Spock-HK2 expects org.glassfish.hk2:hk2-locator dependency to be present on the classpath. It is tested with HK2 version of 2.3.0.

Usage

Spock-HK2 provides @UseBinders annotation to define HK2 binders to be used in a given specification and its subclasses. This allows you to inject components into Spock specifications.

@UseBinders(YourBinder)
class ExampleSpec extends Specification {

    @Inject
    YourComponent injectedComponent

    def "should inject components into spec fields"() {
        expect:
        injectedComponent != null
    }

}

You can provide either a single binder or a list of binder classes.

Binder instances

The example above defined binder classes to be used in an integration test. You can also define a binder instance or instances instead or besides binder classes: @UseBinders(instances = { new MyBinder() }) or @UseBinders(instances = { [new MyBinder(), new MyOtherBinder()] }).

Other features

You may define your binders in a superclass, e.g. in a common IntegrationSpec abstract specification. You can inject into @Shared fields as well. Consult the project's tests for more examples.

License

Copyright (C) 2015 Piotr Betkier

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0      

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
0.1.0