No description or website provided.
Java
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.gitignore
CHANGELOG.md
LICENSE
README.md
pom.xml

README.md

Chameleon

Build Status

DISCLAIMER: The main motivation for this project was JUnit-BDD project before I decided to upgrade that project to Java 8. Since this project is not used there anymore I've stopped working on this project. This repository will most likely be deleted soon but the artifacts will, of course, remain available on the maven central.

Chameleon is a relatively small, simple library used for creation of proxies at runtime.

Supported target types are interfaces and non final classes. If target type is a class the class does not need to have default/no-arg constructor!

Note: chameleon uses cglib and Objenesis libraries.

Usage

class Example {

    private final String name;

    Example(String name) {
        this.name = name;
    }

    String getName() {
        return name;
    }
}

MimicStrategy<Example> naiveLoggingMimicStrategy = new MimicStrategy<Example>() {

    public Object mimic(Example target, Method mimickedMethod, Object[] arguments) throws Throwable {
        String methodName = mimickedMethod.getName();
        String targetClassName = target.getClass().getSimpleName();
        String format = "Executing method %s on instance of %s with arguments %s.";
        System.out.println(String.format(format, methodName, targetClassName, Arrays.toString(arguments)));
        return mimickedMethod.invoke(target, arguments);
    }
};

Example abc = mimic(new Example("abc"), naiveLoggingMimicStrategy);
abc.getName();

In this example we use Chameleon to create a proxy of the immutable class Example to add naive logging behaviour.

Installation

Maven

Add the following dependency to you pom.xml:

<dependency>
    <groupId>com.github.lpandzic.chameleon</groupId>
    <artifactId>chameleon</artifactId>
    <version>1.2</version>
</dependency>

Changes

See the Changelog

Credits

Continuous Integration provided by:

Powered by CloudBees

Thanks to the following library creators and maintainers:

Objenesis

Code Generation Library