-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#89] Added possibility to add NotNull at method, fluent interface an…
…d wrapping FluentApi Type. Additionally added logic to overrule Validators i.e. with Nullable for NotNull
- Loading branch information
1 parent
a88ba41
commit 6398bd5
Showing
5 changed files
with
182 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...r/src/test/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethodParameterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package io.toolisticon.fluapigen.processor; | ||
|
||
import io.toolisticon.aptk.cute.APTKUnitTestProcessor; | ||
import io.toolisticon.aptk.tools.wrapper.VariableElementWrapper; | ||
import io.toolisticon.cute.Cute; | ||
import io.toolisticon.cute.PassIn; | ||
import io.toolisticon.fluapigen.validation.api.Matches; | ||
import io.toolisticon.fluapigen.validation.api.NotNull; | ||
import io.toolisticon.fluapigen.validation.api.Nullable; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.Test; | ||
|
||
import javax.annotation.processing.ProcessingEnvironment; | ||
import javax.lang.model.element.VariableElement; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Unit test for {@link ModelInterfaceMethodParameter}. | ||
*/ | ||
public class ModelInterfaceMethodParameterTest { | ||
|
||
interface TestClassWithoutValidators { | ||
|
||
public void testMethod(@PassIn String parameter); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void test_getValidators_withoutValidatorsPresent() { | ||
Cute.unitTest().when().passInElement().<VariableElement>fromClass(TestClassWithoutValidators.class) | ||
.intoUnitTest(new APTKUnitTestProcessor<VariableElement>() { | ||
@Override | ||
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, VariableElement variableElement) { | ||
|
||
ModelInterfaceMethodParameter unit = new ModelInterfaceMethodParameter(VariableElementWrapper.wrap(variableElement), null, null); | ||
|
||
MatcherAssert.assertThat("Expect to find no validators", !unit.hasValidators()); | ||
|
||
} | ||
}).executeTest(); | ||
} | ||
|
||
@NotNull | ||
interface TestClassWithValidators { | ||
|
||
public void testMethod(@PassIn @Matches(".*[@].*") String parameter); | ||
|
||
} | ||
|
||
@Test | ||
public void test_getValidators_withValidatorsPresent() { | ||
Cute.unitTest().when().passInElement().<VariableElement>fromClass(TestClassWithValidators.class) | ||
.intoUnitTest(new APTKUnitTestProcessor<VariableElement>() { | ||
@Override | ||
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, VariableElement variableElement) { | ||
|
||
ModelInterfaceMethodParameter unit = new ModelInterfaceMethodParameter(VariableElementWrapper.wrap(variableElement), null, null); | ||
|
||
MatcherAssert.assertThat("Expect to find validators", unit.hasValidators()); | ||
MatcherAssert.assertThat("Expect to find 2 validators", unit.getValidators().size() == 2); | ||
MatcherAssert.assertThat(unit.getValidators().stream().map(e -> e.getAnnotationMirrorWrapper().asTypeMirror().getQualifiedName()).collect(Collectors.toList()), Matchers.containsInAnyOrder(NotNull.class.getCanonicalName(), Matches.class.getCanonicalName())); | ||
|
||
|
||
} | ||
}).executeTest(); | ||
} | ||
|
||
@NotNull | ||
interface TestClassWithOverruledValidators { | ||
|
||
void testMethod(@PassIn @Nullable @Matches(".*[@].*") String parameter); | ||
|
||
} | ||
|
||
@Test | ||
public void test_getValidators_withOverruledValidatorsPresent() { | ||
Cute.unitTest().when().passInElement().<VariableElement>fromClass(TestClassWithOverruledValidators.class) | ||
.intoUnitTest(new APTKUnitTestProcessor<VariableElement>() { | ||
@Override | ||
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, VariableElement variableElement) { | ||
|
||
ModelInterfaceMethodParameter unit = new ModelInterfaceMethodParameter(VariableElementWrapper.wrap(variableElement), null, null); | ||
|
||
MatcherAssert.assertThat("Expect to find validators", unit.hasValidators()); | ||
MatcherAssert.assertThat("Expect to find 2 validators", unit.getValidators().size() == 2); | ||
MatcherAssert.assertThat(unit.getValidators().stream().map(e -> e.getAnnotationMirrorWrapper().asTypeMirror().getQualifiedName()).collect(Collectors.toList()), Matchers.containsInAnyOrder(Nullable.class.getCanonicalName(), Matches.class.getCanonicalName())); | ||
|
||
|
||
} | ||
}).executeTest(); | ||
} | ||
|
||
@Nullable | ||
interface TestClassWithOverruledValidators2 { | ||
|
||
void testMethod(@PassIn @NotNull @Matches(".*[@].*") String parameter); | ||
|
||
} | ||
|
||
@Test | ||
public void test_getValidators_withOverruledValidatorsPresent2() { | ||
Cute.unitTest().when().passInElement().<VariableElement>fromClass(TestClassWithOverruledValidators2.class) | ||
.intoUnitTest(new APTKUnitTestProcessor<VariableElement>() { | ||
@Override | ||
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, VariableElement variableElement) { | ||
|
||
ModelInterfaceMethodParameter unit = new ModelInterfaceMethodParameter(VariableElementWrapper.wrap(variableElement), null, null); | ||
|
||
MatcherAssert.assertThat("Expect to find validators", unit.hasValidators()); | ||
MatcherAssert.assertThat("Expect to find 2 validators", unit.getValidators().size() == 2); | ||
MatcherAssert.assertThat(unit.getValidators().stream().map(e -> e.getAnnotationMirrorWrapper().asTypeMirror().getQualifiedName()).collect(Collectors.toList()), Matchers.containsInAnyOrder(NotNull.class.getCanonicalName(), Matches.class.getCanonicalName())); | ||
|
||
|
||
} | ||
}).executeTest(); | ||
} | ||
|
||
} |