mirrormocks

Set of mock classes for javax.lang.model interfaces. For use in unit testing annotation processors.

License

License

Categories

Categories

Mirror Application Layer Libs Introspection ORM Data
GroupId

GroupId

com.flarestarsoftware
ArtifactId

ArtifactId

mirrormocks
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

mirrormocks
Set of mock classes for javax.lang.model interfaces. For use in unit testing annotation processors.
Project URL

Project URL

https://github.com/diosmosis/java-mirror-mocks
Source Code Management

Source Code Management

https://github.com/diosmosis/java-mirror-mocks

Download mirrormocks

How to add to project

<!-- https://jarcasting.com/artifacts/com.flarestarsoftware/mirrormocks/ -->
<dependency>
    <groupId>com.flarestarsoftware</groupId>
    <artifactId>mirrormocks</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.flarestarsoftware/mirrormocks/
implementation 'com.flarestarsoftware:mirrormocks:0.2.0'
// https://jarcasting.com/artifacts/com.flarestarsoftware/mirrormocks/
implementation ("com.flarestarsoftware:mirrormocks:0.2.0")
'com.flarestarsoftware:mirrormocks:jar:0.2.0'
<dependency org="com.flarestarsoftware" name="mirrormocks" rev="0.2.0">
  <artifact name="mirrormocks" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.flarestarsoftware', module='mirrormocks', version='0.2.0')
)
libraryDependencies += "com.flarestarsoftware" % "mirrormocks" % "0.2.0"
[com.flarestarsoftware/mirrormocks "0.2.0"]

Dependencies

compile (1)

Group / Artifact Type Version
org.reflections : reflections jar 0.9.10

Project Modules

There are no modules declared in this project.

java-mirror-mocks

Description

A set of mock classes for the interfaces in the javax.lang.model package. For use in unit testing code in annotation processors.

Usage

The implementations provided by this package use reflection to mimic the mirror API as closely as possible. So to use it during tests, first create a test class that you'd want a Element for, eg:

@MyAnnotationToProcess
public class TestClassWithAnnotation {
    // ...
}

then create the Element using ElementFactory:

import flarestar.mirror.mock.element.ElementFactory;

public class MyAnnotationProcessorComponentTest {

    private MyAnnotationProcessorComponent instance = new MyAnnotationProcessorComponent();

    @Test
    public void testSomething() {
        TypeElement mockElement = ElementFactory.make(TestClassWithAnnotation.class);

        instance.doSomething(mockElement);
    }

This should result in viable unit tests w/o the verbosity that comes hand in hand w/ using mocking frameworks like mockito.

Caveat

The mirror API is very strange. There are many corner cases that are either impossible to replicate via reflection or are cases where I am not positive what the actual behavior should be. So in some cases these mocks may not behave as expected.

It is thus recommended to couple unit tests w/ integration tests that invoke annotation processors through the compiler API. This way, you can get a larger amount of code coverage and the confidence for success in the real world from integration tests, plus easier debugging when performing refactoring from your unit tests.

Versions

Version
0.2.0
0.1.0