org.springframework.test.util.AopTestUtils Java Examples
The following examples show how to use
org.springframework.test.util.AopTestUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReflectionUtils.java From embedded-database-spring-test with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T> T getField(Object targetObject, String name) { Assert.notNull(targetObject, "Target object must not be null"); targetObject = AopTestUtils.getUltimateTargetObject(targetObject); Class<?> targetClass = targetObject.getClass(); Field field = org.springframework.util.ReflectionUtils.findField(targetClass, name); if (field == null) { throw new IllegalArgumentException(String.format("Could not find field '%s' on %s", name, safeToString(targetObject))); } org.springframework.util.ReflectionUtils.makeAccessible(field); return (T) org.springframework.util.ReflectionUtils.getField(field, targetObject); }
Example #2
Source File: BookRepositoryCachingIntegrationTest.java From tutorials with MIT License | 5 votes |
@BeforeEach void setUp() { mock = AopTestUtils.getTargetObject(bookRepository); reset(mock); when(mock.findFirstByTitle(eq("Foundation"))) .thenReturn(of(FOUNDATION)); when(mock.findFirstByTitle(eq("Dune"))) .thenReturn(of(DUNE)) .thenThrow(new RuntimeException("Book should be cached!")); }
Example #3
Source File: DemoMockBusinessTest.java From maven-archetype with GNU Lesser General Public License v2.1 | 5 votes |
/** * 实例化之前,设置 mock 类到实体类。 */ @Before public void before() throws Exception { control = EasyMock.createNiceControl(); mockTestMapper = control.createMock(TestMapper.class); ReflectionTestUtils.setField(AopTestUtils.getTargetObject(testBusiness), "testMapper", mockTestMapper); }
Example #4
Source File: SpringAop_1_Test.java From spring-test-examples with Apache License 2.0 | 4 votes |
@Test public void testFooService() { assertNotEquals(fooService.getClass(), FooServiceImpl.class); assertTrue(AopUtils.isAopProxy(fooService)); assertTrue(AopUtils.isCglibProxy(fooService)); assertEquals(AopProxyUtils.ultimateTargetClass(fooService), FooServiceImpl.class); assertEquals(AopTestUtils.getTargetObject(fooService).getClass(), FooServiceImpl.class); assertEquals(AopTestUtils.getUltimateTargetObject(fooService).getClass(), FooServiceImpl.class); assertEquals(fooService.incrementAndGet(), 0); assertEquals(fooService.incrementAndGet(), 0); }
Example #5
Source File: SpringBootAopTest.java From spring-test-examples with Apache License 2.0 | 4 votes |
@Test public void testFooService() { assertNotEquals(fooService.getClass(), FooServiceImpl.class); assertTrue(AopUtils.isAopProxy(fooService)); assertTrue(AopUtils.isCglibProxy(fooService)); assertEquals(AopProxyUtils.ultimateTargetClass(fooService), FooServiceImpl.class); assertEquals(AopTestUtils.getTargetObject(fooService).getClass(), FooServiceImpl.class); assertEquals(AopTestUtils.getUltimateTargetObject(fooService).getClass(), FooServiceImpl.class); assertEquals(fooService.incrementAndGet(), 0); assertEquals(fooService.incrementAndGet(), 0); verify(fooAspect, times(2)).changeIncrementAndGet(any()); }
Example #6
Source File: SpringAop_2_Test.java From spring-test-examples with Apache License 2.0 | 4 votes |
@Test public void testFooService() { assertNotEquals(fooService.getClass(), FooServiceImpl.class); assertTrue(AopUtils.isAopProxy(fooService)); assertTrue(AopUtils.isCglibProxy(fooService)); assertEquals(AopProxyUtils.ultimateTargetClass(fooService), FooServiceImpl.class); assertEquals(AopTestUtils.getTargetObject(fooService).getClass(), FooServiceImpl.class); assertEquals(AopTestUtils.getUltimateTargetObject(fooService).getClass(), FooServiceImpl.class); assertEquals(fooService.incrementAndGet(), 0); assertEquals(fooService.incrementAndGet(), 0); verify(fooAspect, times(2)).changeIncrementAndGet(any()); }