package org.apereo.cas.authentication.mfa.trigger;

import org.apereo.cas.authentication.adaptive.geo.GeoLocationRequest;
import org.apereo.cas.authentication.adaptive.geo.GeoLocationResponse;
import org.apereo.cas.authentication.principal.Service;
import org.apereo.cas.authentication.trigger.AdaptiveMultifactorAuthenticationTrigger;
import org.apereo.cas.configuration.CasConfigurationProperties;

import lombok.val;
import org.junit.jupiter.api.Test;
import org.springframework.context.ApplicationContext;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

/**
 * This is {@link AdaptiveMultifactorAuthenticationTriggerTests}.
 *
 * @author Misagh Moayyed
 * @since 6.1.0
 */
public class AdaptiveMultifactorAuthenticationTriggerTests extends BaseMultifactorAuthenticationTriggerTests {
    @Test
    public void verifyOperationByRequestIP() {
        val props = new CasConfigurationProperties();
        props.getAuthn().getAdaptive().getRequireMultifactor().put("mfa-dummy", "185.86.151.11");
        val trigger = new AdaptiveMultifactorAuthenticationTrigger(this.geoLocationService, props, mock(ApplicationContext.class));
        val result = trigger.isActivated(authentication, registeredService, this.httpRequest, mock(Service.class));
        assertTrue(result.isPresent());
    }

    @Test
    public void verifyOperationByRequestUserAgent() {
        val props = new CasConfigurationProperties();
        props.getAuthn().getAdaptive().getRequireMultifactor().put("mfa-dummy", "^Mozilla.+");
        val trigger = new AdaptiveMultifactorAuthenticationTrigger(this.geoLocationService, props, mock(ApplicationContext.class));
        val result = trigger.isActivated(authentication, registeredService, this.httpRequest, mock(Service.class));
        assertTrue(result.isPresent());
    }

    @Test
    public void verifyOperationByRequestGeoLocation() {
        val props = new CasConfigurationProperties();
        props.getAuthn().getAdaptive().getRequireMultifactor().put("mfa-dummy", ".+London.+");
        val geoResponse = new GeoLocationResponse();
        geoResponse.addAddress("123 Main St London UK");
        when(this.geoLocationService.locate(anyString(), any(GeoLocationRequest.class))).thenReturn(geoResponse);
        val trigger = new AdaptiveMultifactorAuthenticationTrigger(this.geoLocationService, props, mock(ApplicationContext.class));
        val result = trigger.isActivated(authentication, registeredService, this.httpRequest, mock(Service.class));
        assertTrue(result.isPresent());
    }
}

@@ -451,63 +451,8 @@
 est;
-%0Aimport org.springframework.context.ApplicationContext;
 %0A%0Aim
@@ -1067,38 +1067,38 @@
 Service, props, 
-mock(A
+this.a
 pplicationContex
@@ -1090,39 +1090,32 @@
 plicationContext
-.class)
 );%0A        val r
@@ -1568,38 +1568,38 @@
 Service, props, 
-mock(A
+this.a
 pplicationContex
@@ -1591,39 +1591,32 @@
 plicationContext
-.class)
 );%0A        val r
@@ -2307,14 +2307,14 @@
 ps, 
-mock(A
+this.a
 ppli
@@ -2326,23 +2326,16 @@
 nContext
-.class)
 );%0A     

fix tests