All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ehoffman.test.aspects.HasPublicIpAdvice Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package org.ehoffman.test.aspects;

import java.util.concurrent.atomic.AtomicReference;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.ehoffman.resources.NetworkUtils;

/**
 * Will check once that you have a publicly accessible IP address.
 * 
 * Your test will automatically become non-deterministic when you user remote resources.
 * Non-deterministic tests kill kittens... one of these kittens
* * * * @author rex */ public class HasPublicIpAdvice implements MethodInterceptor { private AtomicReference publicIp = new AtomicReference<>(null); public HasPublicIpAdvice() { } @Override public Object invoke(final MethodInvocation invocation) throws Throwable { if (publicIp.get() != null) { publicIp.compareAndSet(null, NetworkUtils.getMyPublicIp()); } if (publicIp.get() != null) { return invocation.proceed(); } else { throw new SkipException(this); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy