Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to mock organization #112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .circleci/config.yml

This file was deleted.

6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# SpringMockK

[![CircleCI](https://circleci.com/gh/Ninja-Squad/springmockk.svg?style=svg)](https://circleci.com/gh/Ninja-Squad/springmockk)

Support for Spring Boot integration tests written in Kotlin using [MockK](https://mockk.io/) instead of Mockito.

Spring Boot provides `@MockBean` and `@SpyBean` annotations for integration tests, which create mock/spy beans using Mockito.
Expand Down Expand Up @@ -42,7 +40,7 @@ class GreetingControllerTest {

Add this to your dependencies:
```kotlin
testImplementation("com.ninja-squad:springmockk:4.0.2")
testImplementation("io.mockk:springmockk:4.0.2")
```

If you want to make sure Mockito (and the standard `MockBean` and `SpyBean` annotations) is not used, you can also exclude the mockito dependency:
Expand All @@ -57,7 +55,7 @@ testImplementation("org.springframework.boot:spring-boot-starter-test") {
Add this to your dependencies:
```xml
<dependency>
<groupId>com.ninja-squad</groupId>
<groupId>io.mockk</groupId>
<artifactId>springmockk</artifactId>
<version>4.0.2</version>
<scope>test</scope>
Expand Down
16 changes: 8 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.time.Duration

plugins {
// if it's changed, it must also be channged in the bomProperty below
// if it's changed, it must also be changed in the bomProperty below
val kotlinVersion = "1.7.21"

`java-library`
Expand All @@ -16,7 +16,7 @@ plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

group = "com.ninja-squad"
group = "io.mockk"
version = "4.0.2"
description = "MockBean and SpyBean, but for MockK instead of Mockito"

Expand Down Expand Up @@ -117,10 +117,10 @@ publishing {
pom {
name.set(project.name)
description.set(project.description)
url.set("https://github.com/Ninja-Squad/springmockk")
url.set("https://github.com/mockk/springmockk")
organization {
name.set("Ninja Squad")
url.set("http://ninja-squad.com")
name.set("mockk")
url.set("https://github.com/mockk")
}
licenses {
license {
Expand All @@ -137,9 +137,9 @@ publishing {
}
}
scm {
connection.set("scm:git:git://github.com/Ninja-Squad/springmockk")
developerConnection.set("scm:git:git://github.com/Ninja-Squad/springmockk")
url.set("https://github.com/Ninja-Squad/springmockk")
connection.set("scm:git:git://github.com/mockk/springmockk")
developerConnection.set("scm:git:git://github.com/mockk/springmockk")
url.set("https://github.com/mockk/springmockk")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.ninjasquad.springmockk;
package io.mockk.springmockk;

import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AliasFor;
import org.springframework.test.context.junit4.SpringRunner;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand All @@ -7,10 +11,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AliasFor;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Annotation that can be used to add MockK mocks to a Spring {@link ApplicationContext}. Can be
* used as a class level annotation or on fields in either {@code @Configuration} classes,
Expand Down Expand Up @@ -72,7 +72,7 @@
* @author JB Nizet
* @see MockkPostProcessor
*/
@Target({ElementType.TYPE, ElementType.FIELD })
@Target({ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repeatable(MockkBeans.class)
Expand All @@ -82,13 +82,15 @@
* The name of the bean to register or replace. If not specified the name will either
* be generated or, if the mock replaces an existing bean, the existing name will be
* used.
*
* @return the name of the bean
*/
String name() default "";

/**
* The classes to mock. This is an alias of {@link #classes()} which can be used for
* brevity if no other attributes are defined. See {@link #classes()} for details.
*
* @return the classes to mock
*/
@AliasFor("classes")
Expand All @@ -104,32 +106,37 @@
* <p>
* If this is the only specified attribute consider using the {@code value} alias
* instead.
*
* @return the classes to mock
*/
@AliasFor("value")
Class<?>[] classes() default {};

/**
* Any extra interfaces that should also be declared on the mock.
*
* @return any extra interfaces
*/
Class<?>[] extraInterfaces() default {};

/**
* The clear mode to apply to the mock bean. The default is {@link MockkClear#AFTER}
* meaning that mocks are automatically reset after each test method is invoked.
*
* @return the clear mode
*/
MockkClear clear() default MockkClear.AFTER;

/**
* Specifies if the created mock will be relaxed or not
*
* @return true if relaxed, false otherwise
*/
boolean relaxed() default false;

/**
* Specifies if the created mock will have relaxed <code>Unit</code>-returning functions
*
* @return true if relaxed, false otherwise
*/
boolean relaxUnitFun() default false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninjasquad.springmockk;
package io.mockk.springmockk;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand All @@ -22,10 +22,11 @@
@Documented
public @interface MockkBeans {

/**
* Return the contained {@link MockkBean} annotations.
* @return the mockk beans
*/
MockkBean[] value();
/**
* Return the contained {@link MockkBean} annotations.
*
* @return the mockk beans
*/
MockkBean[] value();

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package com.ninjasquad.springmockk;
package io.mockk.springmockk;

import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AliasFor;
import org.springframework.test.context.junit4.SpringRunner;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand All @@ -7,10 +11,6 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.AliasFor;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Annotation that can be used to apply MockK spies to a Spring
* {@link ApplicationContext}. Can be used as a class level annotation or on fields in
Expand Down Expand Up @@ -71,45 +71,49 @@
* @author JB Nizet
* @see MockkPostProcessor
*/
@Target({ ElementType.TYPE, ElementType.FIELD })
@Target({ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Repeatable(SpykBeans.class)
public @interface SpykBean {

/**
* The name of the bean to spy. If not specified the name will either be generated or,
* if the spy is for an existing bean, the existing name will be used.
* @return the name of the bean
*/
String name() default "";
/**
* The name of the bean to spy. If not specified the name will either be generated or,
* if the spy is for an existing bean, the existing name will be used.
*
* @return the name of the bean
*/
String name() default "";

/**
* The classes to spy. This is an alias of {@link #classes()} which can be used for
* brevity if no other attributes are defined. See {@link #classes()} for details.
* @return the classes to spy
*/
@AliasFor("classes")
Class<?>[] value() default {};
/**
* The classes to spy. This is an alias of {@link #classes()} which can be used for
* brevity if no other attributes are defined. See {@link #classes()} for details.
*
* @return the classes to spy
*/
@AliasFor("classes")
Class<?>[] value() default {};

/**
* The classes to spy. Each class specified here will result in a spy being applied.
* Classes can be omitted when the annotation is used on a field.
* <p>
* When {@code @SpykBean} also defines a {@code name} this attribute can only contain a
* single value.
* <p>
* If this is the only specified attribute consider using the {@code value} alias
* instead.
* @return the classes to spy
*/
@AliasFor("value")
Class<?>[] classes() default {};
/**
* The classes to spy. Each class specified here will result in a spy being applied.
* Classes can be omitted when the annotation is used on a field.
* <p>
* When {@code @SpykBean} also defines a {@code name} this attribute can only contain a
* single value.
* <p>
* If this is the only specified attribute consider using the {@code value} alias
* instead.
*
* @return the classes to spy
*/
@AliasFor("value")
Class<?>[] classes() default {};

/**
* The reset mode to apply to the spied bean. The default is {@link MockkClear#AFTER}
* meaning that spies are automatically reset after each test method is invoked.
* @return the reset mode
*/
MockkClear clear() default MockkClear.AFTER;
/**
* The reset mode to apply to the spied bean. The default is {@link MockkClear#AFTER}
* meaning that spies are automatically reset after each test method is invoked.
*
* @return the reset mode
*/
MockkClear clear() default MockkClear.AFTER;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninjasquad.springmockk;
package io.mockk.springmockk;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninjasquad.springmockk
package io.mockk.springmockk

import org.springframework.beans.factory.NoSuchBeanDefinitionException
import org.springframework.context.ApplicationContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninjasquad.springmockk
package io.mockk.springmockk

private const val MULTIPLIER = 31

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninjasquad.springmockk
package io.mockk.springmockk

import org.springframework.core.ResolvableType
import org.springframework.core.annotation.MergedAnnotations
Expand All @@ -9,7 +9,7 @@ import org.springframework.util.StringUtils
import java.lang.reflect.AnnotatedElement
import java.lang.reflect.Field
import java.lang.reflect.TypeVariable
import java.util.Collections
import java.util.*
import kotlin.reflect.KClass


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ninjasquad.springmockk
package io.mockk.springmockk

import java.lang.ref.WeakReference
import java.util.IdentityHashMap

/**
* Clear strategy used on a mockk bean, applied to a mock via the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninjasquad.springmockk
package io.mockk.springmockk

import org.springframework.beans.factory.support.BeanDefinitionRegistry
import org.springframework.context.ConfigurableApplicationContext
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninjasquad.springmockk
package io.mockk.springmockk

import org.springframework.test.context.ContextConfigurationAttributes
import org.springframework.test.context.ContextCustomizer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
package com.ninjasquad.springmockk

import java.util.*
package io.mockk.springmockk

/**
* Beans created using MockK.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninjasquad.springmockk
package io.mockk.springmockk

import io.mockk.mockkClass
import org.springframework.core.ResolvableType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ninjasquad.springmockk
package io.mockk.springmockk

import io.mockk.MockK
import io.mockk.MockKGateway
Expand Down
Loading