-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: calls to default constructors outside the factory should still b…
…e possible, and a default factory is made available (#1448)
- Loading branch information
Showing
2 changed files
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package spoon.test.ctElement; | ||
|
||
import org.junit.Test; | ||
import spoon.Launcher; | ||
import spoon.reflect.declaration.CtElement; | ||
import spoon.support.reflect.declaration.CtAnnotationImpl; | ||
import spoon.support.reflect.declaration.CtMethodImpl; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertSame; | ||
|
||
/** | ||
* Created by urli on 28/06/2017. | ||
*/ | ||
public class ElementTest { | ||
|
||
@Test | ||
public void testGetFactory() { | ||
// contract: getFactory should always return an object | ||
// even if an element is created via its constructor | ||
// and not through the factory | ||
|
||
Launcher spoon = new Launcher(); | ||
|
||
CtElement element = spoon.getFactory().createAnnotation(); | ||
assertNotNull(element.getFactory()); | ||
|
||
CtElement otherElement = new CtAnnotationImpl<>(); | ||
assertNotNull(otherElement.getFactory()); | ||
|
||
CtElement yetAnotherOne = new CtMethodImpl<>(); | ||
assertNotNull(yetAnotherOne.getFactory()); | ||
|
||
// contract: a singleton is used for the default factory | ||
assertSame(otherElement.getFactory(), yetAnotherOne.getFactory()); | ||
} | ||
} |