lundi 24 août 2020

Need to mock a JoinPoint for JUnit test

I need to mock a Spring Java JoinPoint for a JUnit test. See code below.

/**
     * Pointcut that matches all Spring beans in the application's main packages.
     */
    @Pointcut("within(com.cybersite.repository..*)"+
        " || within(com.cybersite.service..*)"+
        " || within(com.cybersite.web.rest..*)")
    public void applicationPackagePointcut() {
        // Method is empty as this is just a Pointcut, the implementations are in the advices.
    }

    /**
     * Retrieves the {@link Logger} associated to the given {@link JoinPoint}.
     *
     * @param joinPoint join point we want the logger for.
     * @return {@link Logger} associated to the given {@link JoinPoint}.
     */
    private Logger logger(JoinPoint joinPoint) {
        return LoggerFactory.getLogger(joinPoint.getSignature().getDeclaringTypeName());
    }

Anyone know how I would create the mock JoinPoint?

Aucun commentaire:

Enregistrer un commentaire