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

v1.7 #26

Merged
merged 2 commits into from
Aug 10, 2024
Merged

v1.7 #26

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
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Simply include the maven dependency (from central maven) to start using @MockInB
<dependency>
<groupId>com.teketik</groupId>
<artifactId>mock-in-bean</artifactId>
<version>boot2-v1.6</version>
<version>boot2-v1.7</version>
<scope>test</scope>
</dependency>
```
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.teketik</groupId>
<artifactId>mock-in-bean</artifactId>
<version>boot2-v1.6</version>
<version>boot2-v1.7</version>
<name>Mock in Bean</name>
<description>Surgically Inject Mockito Mock/Spy in Spring Beans</description>
<url>https://github.com/antoinemeyer/mock-in-bean</url>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/teketik/test/mockinbean/MockInBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
* @author Antoine Meyer
* @see SpyInBean
*/
@Target({ElementType.FIELD})
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(MockInBeans.class)
public @interface MockInBean {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/teketik/test/mockinbean/MockInBeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @author Antoine Meyer
*/
@Target({ElementType.FIELD})
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface MockInBeans {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.teketik.test.mockinbean.test;

import com.teketik.test.mockinbean.test.annotations.MockInBeanWithCustomName;
import com.teketik.test.mockinbean.test.annotations.MockInMultipleComponents;
import com.teketik.test.mockinbean.test.components.MockableComponent1;
import com.teketik.test.mockinbean.test.components.MockableComponent2;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;

class MockInBeanMetaAnnotationsTest extends MockInBeanBaseTest {

@MockInMultipleComponents
private MockableComponent1 mockableComponent1;

@MockInBeanWithCustomName
private MockableComponent2 mockableComponent2;

/**
* Note: Will fail if run individually, run as a class.
*/
@Test
void test() {
Assertions.assertTrue(TestUtils.isMock(mockableComponent1));
Assertions.assertSame(mockableComponent1, ReflectionTestUtils.getField(testComponent1, "mockableComponent1"));
Assertions.assertSame(mockableComponent1, ReflectionTestUtils.getField(testComponent2, "mockableComponent1"));

Assertions.assertTrue(TestUtils.isMock(mockableComponent2));
Assertions.assertSame(mockableComponent2, ReflectionTestUtils.getField(testComponent1, "mockableComponent2"));
Assertions.assertNotSame(mockableComponent2, ReflectionTestUtils.getField(testComponent2, "mockableComponent2"));
Assertions.assertFalse(TestUtils.isMockOrSpy(ReflectionTestUtils.getField(testComponent2, "mockableComponent2")));
}

@Override
MockableComponent1 getMockableComponent1() {
return mockableComponent1;
}

@Override
MockableComponent2 getMockableComponent2() {
return mockableComponent2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.teketik.test.mockinbean.test.annotations;

import com.teketik.test.mockinbean.MockInBean;
import com.teketik.test.mockinbean.test.components.TestComponent1;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@MockInBean(TestComponent1.class)
public @interface MockInBeanWithCustomName {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.teketik.test.mockinbean.test.annotations;

import com.teketik.test.mockinbean.MockInBean;
import com.teketik.test.mockinbean.test.components.TestComponent1;
import com.teketik.test.mockinbean.test.components.TestComponent2;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@MockInBean(TestComponent1.class)
@MockInBean(TestComponent2.class)
public @interface MockInMultipleComponents {
}
Loading