Java tutorial
/* * Copyright (c) 2014 Andrey Paslavsky. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.paslavsky.springrest; import org.springframework.aop.framework.ReflectiveMethodInvocation; import org.springframework.util.ReflectionUtils; import org.testng.Assert; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.lang.reflect.Constructor; import java.lang.reflect.Method; /** * Tests for the {@link net.paslavsky.springrest.SpringRestClientToStringAdvisor.ToStringMethodInterceptor} * * @author Andrey Paslavsky * @version 1.0 */ public class ToStringMethodInterceptorTest { private ReflectiveMethodInvocation invocation; @BeforeMethod public void setUp(Method method) throws Exception { Constructor<?> constructor = ReflectiveMethodInvocation.class.getDeclaredConstructors()[0]; ReflectionUtils.makeAccessible(constructor); invocation = (ReflectiveMethodInvocation) constructor.newInstance(this, this, method, null, getClass(), null); } @Test public void testInvoke() throws Throwable { SpringRestClientToStringAdvisor.ToStringMethodInterceptor interceptor = new SpringRestClientToStringAdvisor.ToStringMethodInterceptor( getClass()); Assert.assertEquals(interceptor.invoke(invocation), toString()); } }