Skip to content

A utility library to handle Java reflection with ease

Notifications You must be signed in to change notification settings

hejian991/reflection-utils

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reflection-utils Icon

Build Status Coverage Status Maven Central Coverity

This library will make it easier to get and set internal fields in classes using java reflection. The library is optimized for convenience and not for speed, so it works best with unit tests.

Mocking is great! Sometimes the easiest way to insert mocks are by Java reflection. Especially if you cannot use constructor arguments or setter methods.

Example

    @Test
    public void storeMethodShouldSaveEntity() throws Exception {
        // Setup entities
        EntityHandler handler = new EntityHandlerImpl();        
        StoreDao storeDao = mock(StoreDao.class);
        
        // Insert mock into handler
        new ReflectionHelper(handler).setField(storeDao);
        
        // Perform method
        handler.store();

        // Verify save method
        verify(storeDao).save();
    }

See more

About

A utility library to handle Java reflection with ease

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%