1

How can I write Junit test for the following code

@Aspect
@Component
@Slf4j
public class SampleAspect {

    @Value("${timeout:10}")
    private long timeout;

    @Around("@annotation(com.packagename.TrackExecutionTime)")
    public Object intercept( ProceedingJoinPoint point) throws Throwable {

        long startTime = System.currentTimeMillis();

        Object obj = point.proceed();

        long endTime  = System.currentTimeMillis();

        long timeOut = endTime-startTime;

        if(timeOut > timeout) 
         {
          log.error("Error occured");
        }
          return obj;
    }

}

So the above aspect need to be tested and covered the if condition as well

DKS
  • 9
  • 3
  • Welcome to SO. Please learn what an [MCVE](https://stackoverflow.com/help/mcve) is and how it helps you to get better answers quicker. What is wrong with this question is that you are not showing what you tried and explaining the expected vs. actual results, but asking the community here to do the whole job for you. For that, you can hire someone via UpWork or so. – kriegaex Mar 23 '22 at 06:28
  • With regard to your question: In order to test your aspect, I recommend a unit test. I see no need to start with an integration test here. I closed the question with a link to an answer showing you how to do that. I also wrote a related answer concerning [aspect integration tests](https://stackoverflow.com/a/41453156/1082681). – kriegaex Mar 23 '22 at 06:29

0 Answers0