// Path: src/main/java/org/wmaop/aop/advice/remit/Remit.java
// public interface Remit {
// 	boolean isApplicable();
// 	boolean isApplicable(Scope scope);
// }
// 
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// 		BEFORE,INVOKE,AFTER;
// 
// }
// 
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
// 
// 	InterceptResult intercept(FlowPosition flowPosition, IData idata);
// 
// 	int getInvokeCount();
// 
// 	String getName();
// 
// 	Map<String, Object> toMap();
// 
// }
// 
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
// public interface PointCut {
// 
// 	boolean isApplicable(FlowPosition pipelinePosition, IData idata);
// 
// 	InterceptPoint getInterceptPoint();
// 
// 	FlowPositionMatcher getFlowPositionMatcher();
// 
// 	Object toMap();
// }


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.advice.remit.Remit;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.interceptor.Interceptor;
import org.wmaop.aop.pointcut.PointCut;
	@Test
	public void shouldResetAdviceForUserAndSession() {
		setupScopedAdvice(adm, true);
		adm.reset(null);
		assertNotNull(adm.getAdvice("advGlobal"));
		assertNull(adm.getAdvice("advSession"));
		assertNull(adm.getAdvice("advUser1"));
		assertNull(adm.getAdvice("advUser2"));
	}

	@Test
	public void shouldTallyInvokeCountForPrefix() {
		adm.reset(Scope.ALL);
		adm.registerAdvice(createAdvice("adv1", Scope.GLOBAL, true));
		adm.registerAdvice(createAdvice("adv2", Scope.GLOBAL, true));
		assertEquals(2, adm.getInvokeCountForPrefix("ad"));
	}

	private void setupScopedAdvice(AdviceManager adm, boolean all) {
		adm.reset(Scope.ALL);
		adm.registerAdvice(createAdvice("advGlobal", Scope.GLOBAL, true));
		adm.registerAdvice(createAdvice("advSession", Scope.SESSION, true));
		adm.registerAdvice(createAdvice("advUser1", Scope.USER, true));
		adm.registerAdvice(createAdvice("advUser2", Scope.USER, all));
	}

	private Advice createAdvice(String id, Scope scope, boolean applicable) {
		Remit remit = mock(Remit.class);
		when(remit.isApplicable(scope)).thenReturn(applicable);
		Advice adv = mock(Advice.class);
// Path: src/main/java/org/wmaop/aop/advice/remit/Remit.java
// public interface Remit {
// 	boolean isApplicable();
// 	boolean isApplicable(Scope scope);
// }
// 
// Path: src/main/java/org/wmaop/aop/interceptor/InterceptPoint.java
// public enum InterceptPoint {
// 		BEFORE,INVOKE,AFTER;
// 
// }
// 
// Path: src/main/java/org/wmaop/aop/interceptor/Interceptor.java
// public interface Interceptor {
// 
// 	InterceptResult intercept(FlowPosition flowPosition, IData idata);
// 
// 	int getInvokeCount();
// 
// 	String getName();
// 
// 	Map<String, Object> toMap();
// 
// }
// 
// Path: src/main/java/org/wmaop/aop/pointcut/PointCut.java
// public interface PointCut {
// 
// 	boolean isApplicable(FlowPosition pipelinePosition, IData idata);
// 
// 	InterceptPoint getInterceptPoint();
// 
// 	FlowPositionMatcher getFlowPositionMatcher();
// 
// 	Object toMap();
// }


// Path: src/test/java/org/wmaop/aop/advice/AdviceManagerTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.wmaop.aop.advice.remit.Remit;
import org.wmaop.aop.interceptor.InterceptPoint;
import org.wmaop.aop.interceptor.Interceptor;
import org.wmaop.aop.pointcut.PointCut;

	@Test
	public void shouldResetAdviceForUserAndSession() {
		setupScopedAdvice(adm, true);
		adm.reset(null);
		assertNotNull(adm.getAdvice("advGlobal"));
		assertNull(adm.getAdvice("advSession"));
		assertNull(adm.getAdvice("advUser1"));
		assertNull(adm.getAdvice("advUser2"));
	}

	@Test
	public void shouldTallyInvokeCountForPrefix() {
		adm.reset(Scope.ALL);
		adm.registerAdvice(createAdvice("adv1", Scope.GLOBAL, true));
		adm.registerAdvice(createAdvice("adv2", Scope.GLOBAL, true));
		assertEquals(2, adm.getInvokeCountForPrefix("ad"));
	}

	private void setupScopedAdvice(AdviceManager adm, boolean all) {
		adm.reset(Scope.ALL);
		adm.registerAdvice(createAdvice("advGlobal", Scope.GLOBAL, true));
		adm.registerAdvice(createAdvice("advSession", Scope.SESSION, true));
		adm.registerAdvice(createAdvice("advUser1", Scope.USER, true));
		adm.registerAdvice(createAdvice("advUser2", Scope.USER, all));
	}

	private Advice createAdvice(String id, Scope scope, boolean applicable) {
		Remit remit = mock(Remit.class);
		when(remit.isApplicable(scope)).thenReturn(applicable);
		Advice adv = mock(Advice.class);
		Interceptor interceptor = mock(Interceptor.class);