I am writing below Spring Unit test code. Unit test @Before method is not getting executed. Since it is directly running @PostConstruct i am getting erorrs Caused by: java.lang.IllegalArgumentException: rate must be positive
because the default value is 0.00. I want to set some value to request max limit so that postcontstruct block will go through smoothly. what is wrong in my code? Please help.
@Component
public class SurveyPublisher {
@Autowired
private SurveyProperties surveyProperties;
@PostConstruct
public void init() {
rateLimiter = RateLimiter.create(psurveyProperties.getRequestMaxLimit());
}
}
public void publish() {
rateLimiter.acquire();
// do something
}
}
//Unit test class
public class SurveyPublisherTest extends AbstractTestNGSpringContextTests {
@Mock
SurveyProperties surveyProperties;
@BeforeMethod
public void init() {
Mockito.when(surveyProperties.getRequestMaxLimit()).thenReturn(40.00);
}
@Test
public void testPublish_noResponse() {
//do some test
}
}