org.fest.reflect.core.Reflection Java Examples
The following examples show how to use
org.fest.reflect.core.Reflection.
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: PlayerServiceImplTest.java From codenjoy with GNU General Public License v3.0 | 6 votes |
@Test public void shouldContinueTicks_whenExceptionInPlayerGameTick() { // given createPlayer(VASYA); Game game1 = createGame(gameField(VASYA)); setNewGames(game1); setup(game1); List list = Reflection.field(PlayerGames.Fields.all).ofType(List.class).in(playerGames).get(); PlayerGame playerGame = (PlayerGame)list.remove(0); PlayerGame spy = spy(playerGame); list.add(spy); doThrow(new RuntimeException()).when(spy).tick(); // when playerService.tick(); // then verify(game1.getField()).quietTick(); }
Example #2
Source File: MethodHandleWeavingIT.java From glowroot with Apache License 2.0 | 6 votes |
@Override public void executeApp() throws Exception { Class<?> methodHandlesClass = Class.forName("java.lang.invoke.MethodHandles"); Object lookup = Reflection.staticMethod("lookup") .in(methodHandlesClass) .invoke(); Class<?> methodTypeClass = Class.forName("java.lang.invoke.MethodType"); Object methodType = Reflection.staticMethod("methodType") .withParameterTypes(Class.class) .in(methodTypeClass) .invoke(String.class); Reflection.method("findVirtual") .withParameterTypes(Class.class, String.class, methodTypeClass) .in(lookup) .invoke(Object.class, "toString", methodType); }
Example #3
Source File: TransactionPluginTest.java From seed with Mozilla Public License 2.0 | 6 votes |
@Test public void initTransactionPluginTest2() { InitState initState = pluginUnderTest.init( mockInitContext(LocalTransactionManager.class, TransactionHandlerTestImpl.class)); Object object = pluginUnderTest.nativeUnitModule(); Assertions.assertThat(object).isNotNull(); Assertions.assertThat(object).isInstanceOf(TransactionModule.class); Set<TransactionMetadataResolver> transactionMetadataResolvers = Reflection.field( "transactionMetadataResolvers").ofType(new TypeRef<Set<TransactionMetadataResolver>>() { }).in(pluginUnderTest).get(); Assertions.assertThat(transactionMetadataResolvers).isNotNull(); TransactionManager transactionManager = Reflection.field("transactionManager").ofType( TransactionManager.class).in(pluginUnderTest).get(); Assertions.assertThat(transactionManager).isNotNull(); Assertions.assertThat(initState).isEqualTo(InitState.INITIALIZED); }
Example #4
Source File: DefaultAssemblerCollectorTest.java From business with Mozilla Public License 2.0 | 5 votes |
@Test public void testCollect() { Collection<BindingStrategy> strategies = underTest .collect(Lists.newArrayList(Dto1.class, Dto2.class, Dto3.class)); Assertions.assertThat(strategies) .hasSize(2); // 2 default assembler implementation Map<Type[], Key<?>> typeVariables = Reflection.field("constructorParamsMap") .ofType(new TypeRef<Map<Type[], Key<?>>>() {}) .in(strategies.iterator().next()) .get(); Assertions.assertThat(typeVariables) .hasSize(3); // 3 dtos }
Example #5
Source File: PhilipsHueImporterAbstractTest.java From fuchsia with Apache License 2.0 | 5 votes |
@Before public void validate() { MockitoAnnotations.initMocks(this); importer = spy(Reflection.constructor().withParameterTypes(BundleContext.class).in(PhilipsHueImporter.class).newInstance(context)); setupInterceptors(); method("validate").in(importer).invoke(); }
Example #6
Source File: EmbeddedHiveServer.java From incubator-sentry with Apache License 2.0 | 5 votes |
@Override public void start() { // Fix for ACCESS-148. Resets a static field // so the default database is created even // though is has been created before in this JVM Reflection.staticField("createDefaultDB") .ofType(boolean.class) .in(HiveMetaStore.HMSHandler.class) .set(false); }
Example #7
Source File: DiagnosticPluginTest.java From seed with Mozilla Public License 2.0 | 5 votes |
@Test public void initPluginTest() { InitContext initContext = mockInitContextForCore(Lists.newArrayList(TestDiagnosticInfoCollector.class)); diagnosticPlugin.init(initContext); @SuppressWarnings("unchecked") Map<String, Class<? extends DiagnosticInfoCollector>> seedModules = Reflection.field( "diagnosticInfoCollectorClasses").ofType(Map.class).in(diagnosticPlugin).get(); assertThat(seedModules).containsExactly( new AbstractMap.SimpleImmutableEntry<String, Class<? extends DiagnosticInfoCollector>>("test", TestDiagnosticInfoCollector.class)); }
Example #8
Source File: TransactionPluginTest.java From seed with Mozilla Public License 2.0 | 5 votes |
@Test public void initTransactionPluginTest7() { InitState initState = pluginUnderTest.init(mockInitContext(null, TransactionHandlerTestImpl.class)); Assertions.assertThat(initState).isEqualTo(InitState.INITIALIZED); Set<TransactionMetadataResolver> transactionMetadataResolvers = Reflection.field( "transactionMetadataResolvers").ofType(new TypeRef<Set<TransactionMetadataResolver>>() { }).in(pluginUnderTest).get(); Assertions.assertThat(transactionMetadataResolvers).isNotNull(); TransactionManager transactionManager = Reflection.field("transactionManager").ofType( TransactionManager.class).in(pluginUnderTest).get(); Assertions.assertThat(transactionManager).isNotNull(); }
Example #9
Source File: ConfigurationRoleMappingUnitTest.java From seed with Mozilla Public License 2.0 | 5 votes |
@Test public void readConfiguration_should_fill_map() { SecurityConfig securityConfig = new SecurityConfig() .addRole("foo", Sets.newHashSet("bar.foo", "foo.bar")); underTest.readConfiguration(securityConfig); Map<String, Set<String>> roleMap = Reflection.field("map").ofType(new TypeRef<Map<String, Set<String>>>() { }).in(underTest).get(); Set<String> roles = roleMap.get("bar.foo"); assertTrue(roles.contains("foo")); Set<String> roles2 = roleMap.get("foo.bar"); assertTrue(roles2.contains("foo")); }
Example #10
Source File: ConfigurationRoleMappingUnitTest.java From seed with Mozilla Public License 2.0 | 5 votes |
@Before public void before() { underTest = new ConfigurationRoleMapping(); Set<String> mappedRoles = new HashSet<>(); mappedRoles.add(mappedRole1); mappedRoles.add(mappedRole2); map.put(role, mappedRoles); Reflection.field("map").ofType(new TypeRef<Map<String, Set<String>>>() { }).in(underTest).set(map); Reflection.field("scopeClasses").ofType(new TypeRef<Map<String, Class<? extends Scope>>>() { }).in(underTest).set(new HashMap<>()); }
Example #11
Source File: ConfigurationRolePermissionResolverUnitTest.java From seed with Mozilla Public License 2.0 | 5 votes |
@Test public void readConfiguration_should_build_roles() { SecurityConfig securityConfig = new SecurityConfig().addRolePermissions("foo", Sets.newHashSet("bar", "foobar")); underTest.readConfiguration(securityConfig); Map<String, Set<String>> map = Reflection.field("roles").ofType(new TypeRef<Map<String, Set<String>>>() { }).in(underTest).get(); Set<String> permissions = map.get("foo"); assertTrue(permissions.contains("bar")); assertTrue(permissions.contains("foobar")); }
Example #12
Source File: ConfigurationRolePermissionResolverUnitTest.java From seed with Mozilla Public License 2.0 | 5 votes |
@Test public void resolvePermissionsInRole_should_return_permissions() { Map<String, Set<String>> rolesMap = Reflection.field("roles").ofType(new TypeRef<Map<String, Set<String>>>() { }).in(underTest).get(); Set<String> permissions = new HashSet<>(); permissions.add("bar"); rolesMap.put("foo", permissions); underTest.resolvePermissionsInRole(new Role("foo")); }
Example #13
Source File: MergeSingleImplTest.java From business with Mozilla Public License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void assertMultiple(MergeFromRepository<?> to, Object dto, Class<?>[] classes) { Class<? extends AggregateRoot<?>>[] aggregateClasses = Reflection.field("aggregateClasses") .ofType(Class[].class) .in(to) .get(); Assertions.assertThat(aggregateClasses) .isEqualTo(classes); Stream<Object> stream = Reflection.field("dtoStream") .ofType(Stream.class) .in(to) .get(); Assertions.assertThat(stream.findFirst()) .contains(dto); }
Example #14
Source File: MergeSingleImplTest.java From business with Mozilla Public License 2.0 | 5 votes |
private void assertToMethod(MergeFromRepository<?> to, Object dto, Class<?>... classes) { if (to instanceof MergeMultipleTuplesFromRepositoryImpl) { assertMultiple(to, dto, classes); } else if (to instanceof MergeSingleTupleFromRepositoryImpl) { assertMultiple(Reflection.field("multipleMerger") .ofType(MergeMultipleTuplesFromRepositoryImpl.class) .in(to) .get(), dto, classes); } }
Example #15
Source File: ElsaMakerTest.java From elsa with Apache License 2.0 | 4 votes |
@Test public void objectStackNoRef(){ ElsaSerializerPojo ser = new ElsaMaker().referenceDisable().make(); Object stack = Reflection.method("newElsaStack").withReturnType(ElsaStack.class).in(ser).invoke(); assertTrue(stack instanceof ElsaStack.NoReferenceStack); }
Example #16
Source File: PlayerGamesViewTest.java From codenjoy with GNU General Public License v3.0 | 4 votes |
private HeroData getHeroData(int level, Point coordinate, Object additionalData) { HeroData result = new HeroDataImpl(level, coordinate, MultiplayerType.SINGLE.isMultiplayer()); Reflection.field("additionalData").ofType(Object.class).in(result).set(additionalData); return result; }
Example #17
Source File: ElsaMakerTest.java From elsa with Apache License 2.0 | 4 votes |
@Test public void objectStackDefault(){ ElsaSerializerPojo ser = new ElsaMaker().referenceArrayEnable().make(); Object stack = Reflection.method("newElsaStack").withReturnType(ElsaStack.class).in(ser).invoke(); assertTrue(stack instanceof ElsaStack.IdentityArray); }
Example #18
Source File: ElsaMakerTest.java From elsa with Apache License 2.0 | 4 votes |
@Test public void objectStackHash(){ ElsaSerializerPojo ser = new ElsaMaker().referenceHashMapEnable().make(); Object stack = Reflection.method("newElsaStack").withReturnType(ElsaStack.class).in(ser).invoke(); assertTrue(stack instanceof ElsaStack.MapStack); assertTrue(((ElsaStack.MapStack)stack).data instanceof HashMap); }
Example #19
Source File: ElsaMakerTest.java From elsa with Apache License 2.0 | 4 votes |
@Test public void objectStackIdentHash(){ ElsaSerializerPojo ser = new ElsaMaker().make(); Object stack = Reflection.method("newElsaStack").withReturnType(ElsaStack.class).in(ser).invoke(); assertTrue(stack instanceof ElsaStack.MapStack); assertTrue(((ElsaStack.MapStack)stack).data instanceof IdentityHashMap); }