org.ehoffman.test.aspects.HasPublicIpAdvice Maven / Gradle / Ivy
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);
}
}
}