Skip to content

Commit

Permalink
Merge pull request #26 from antoinemeyer/v1.7
Browse files Browse the repository at this point in the history
v1.7
  • Loading branch information
antoinemeyer authored Aug 10, 2024
2 parents c71daa0 + e417bb0 commit 1e9be00
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 4 deletions.
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 {
}

0 comments on commit 1e9be00

Please sign in to comment.