I want to run some lines of code before this line runs:
@Autowired
private SomeClass a;
I'm working on a testing class, I tried @Before, but the @Autowired runs before the code in the @Before, so there is another solution to run code before the autowiring is happening?
This is the code:
Test class:
private classX x;
@Mock
private classA a;
@Autowired
private classB b;
@Before
private void setUpMockResponse() {
when(a.getMeB()).thenReturn(b);
}
classX code:
// Constructor of classX class.
public classX(classA a) {
this.a = a;
this.b = a.getMeB();
}
If there is any solution to the problem I would be happy to see, the problem is that i need the code in the setUpMockResponse to happen before the autowiring to the classX happens because in the constructor i get b from method on a which is a mock so i need to first set a response when calling the method getMeB(), and also i need b to be autowired.