-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d129b7
commit e4763fe
Showing
6 changed files
with
132 additions
and
12 deletions.
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
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,62 @@ | ||
package net.jbock.coerce; | ||
|
||
import net.jbock.compiler.EvaluatingProcessor; | ||
import net.jbock.compiler.TypeTool; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.lang.model.element.TypeElement; | ||
import javax.lang.model.type.DeclaredType; | ||
import javax.lang.model.type.TypeMirror; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class ResolverTest { | ||
|
||
@Test | ||
void resolves() { | ||
|
||
EvaluatingProcessor.source( | ||
"package test;", | ||
"", | ||
"import java.util.function.Supplier;", | ||
"", | ||
"interface StringSupplier extends Supplier<String> { }", | ||
"", | ||
"abstract class Foo implements StringSupplier { }" | ||
).run("Mapper", (elements, types) -> { | ||
TypeTool tool = new TypeTool(elements, types); | ||
TypeElement mapper = elements.getTypeElement("test.Foo"); | ||
Optional<TypeMirror> result = Resolver.typecheck(Supplier.class, mapper.asType(), tool); | ||
assertTrue(result.isPresent()); | ||
TypeMirror typeMirror = result.get(); | ||
DeclaredType declared = TypeTool.asDeclared(typeMirror); | ||
assertEquals(1, declared.getTypeArguments().size()); | ||
TypeMirror typeParameter = declared.getTypeArguments().get(0); | ||
TypeElement string = elements.getTypeElement("java.lang.String"); | ||
assertTrue(types.isSameType(string.asType(), typeParameter)); | ||
}); | ||
} | ||
|
||
@Test | ||
void doesNotResolve() { | ||
|
||
EvaluatingProcessor.source( | ||
"package test;", | ||
"", | ||
"import java.util.function.Supplier;", | ||
"", | ||
"interface StringSupplier extends Supplier<String> { }", | ||
"", | ||
"abstract class Foo implements StringSupplier { }" | ||
).run("Mapper", (elements, types) -> { | ||
TypeTool tool = new TypeTool(elements, types); | ||
TypeElement mapper = elements.getTypeElement("test.Foo"); | ||
Optional<TypeMirror> result = Resolver.typecheck(String.class, mapper.asType(), tool); | ||
assertFalse(result.isPresent()); | ||
}); | ||
} | ||
} |
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