"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/test/groovy/lang/MixinAnnotationTest.groovy" between
apache-groovy-src-3.0.8.zip and apache-groovy-src-3.0.9.zip

About: Groovy is an agile dynamic (scripting) language for the Java Platform. It has features similar to those of Python, Ruby, Perl, and Smalltalk. Source release.

MixinAnnotationTest.groovy  (apache-groovy-src-3.0.8):MixinAnnotationTest.groovy  (apache-groovy-src-3.0.9)
skipping to change at line 21 skipping to change at line 21
* *
* Unless required by applicable law or agreed to in writing, * Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an * software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the * KIND, either express or implied. See the License for the
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package groovy.lang package groovy.lang
import groovy.test.GroovyShellTestCase
import org.codehaus.groovy.reflection.ReflectionCache import org.codehaus.groovy.reflection.ReflectionCache
import org.junit.After
import org.junit.Test
class MixinAnnotationTest extends GroovyShellTestCase { import static groovy.test.GroovyAssert.assertScript
void testSingleMixinAnnotation () { final class MixinAnnotationTest {
evaluate """
interface Mixed { @Test
def getA () void testSingleMixinAnnotation() {
} assertScript '''
interface Mixed {
@Category(Mixed) def getA()
class CategoryToUse { }
static def msg = "under category: "
@Category(Mixed)
def asText () { class CategoryToUse {
msg + this + ": " + a private static String msg = 'under category: '
} String asText() {
} msg + this + ': ' + a
}
@Mixin(CategoryToUse) }
class ClassToExtend implements Mixed{
String toString () { @Mixin(CategoryToUse)
"object of ClassToExtend" class ClassToExtend implements Mixed {
} String toString() {
'object of ClassToExtend'
def a = "blah" }
} def a = 'blah'
}
groovy.test.GroovyTestCase.assertEquals("under category: object of Class
ToExtend: blah", new ClassToExtend().asText ()) def result = new ClassToExtend().asText()
assert result == 'under category: object of ClassToExtend: blah'
boolean failed = false; groovy.test.GroovyAssert.shouldFail(MissingMethodException) {
try { new Object().asText()
new Object().asText () }
} '''
catch (MissingMethodException e) {
failed = true;
}
assert failed
"""
} }
@Test
void testMultipleMixinAnnotation () { void testMultipleMixinAnnotation () {
evaluate """ assertScript '''
@Category(Object) @Category(Object)
class CategoryToUse1 { class CategoryToUse1 {
def asText () { def asText() {
"under category: " + asBiggerText () 'under category: ' + asBiggerText()
} }
} }
@Category(Object) @Category(Object)
class CategoryToUse2 { class CategoryToUse2 {
def asBiggerText () { def asBiggerText() {
"under BIG category: " + this 'under BIG category: ' + this
} }
} }
@Mixin([CategoryToUse1, CategoryToUse2]) @Mixin([CategoryToUse1, CategoryToUse2])
class ClassToExtend { class ClassToExtend {
String toString () { String toString() {
"object of ClassToExtend" 'object of ClassToExtend'
} }
} }
groovy.test.GroovyTestCase.assertEquals("under category: under BIG categ def result = new ClassToExtend().asText()
ory: object of ClassToExtend", new ClassToExtend().asText ()) assert result == 'under category: under BIG category: object of Clas
""" sToExtend'
} '''
}
protected void tearDown() {
super.tearDown() @Test // GROOVY-10200
ReflectionCache.getCachedClass(ArrayList).setNewMopMethods (null) void testStaticInnerMixinAnnotation() {
ReflectionCache.getCachedClass(List).setNewMopMethods (null) assertScript '''
class A {
def getB() {
'works'
}
}
class C {
@Mixin(A)
static class D {
def test() {
return b
}
}
}
def result = new C.D().test()
assert result == 'works'
'''
}
@After
void tearDown() {
ReflectionCache.getCachedClass(ArrayList).setNewMopMethods(null)
ReflectionCache.getCachedClass(List).setNewMopMethods(null)
} }
// void testOneClass () { // void testOneClass () {
// List.mixin ListExt // List.mixin ListExt
// ArrayList.mixin ArrayListExt // ArrayList.mixin ArrayListExt
// assertEquals 1, [0,1].swap () [0] // assertEquals 1, [0,1].swap () [0]
// assertEquals 0, [0,1].swap () [1] // assertEquals 0, [0,1].swap () [1]
// assertEquals 0, [0,1].swap ().unswap () [0] // assertEquals 0, [0,1].swap ().unswap () [0]
// assertEquals 1, [0,1].swap ().unswap () [1] // assertEquals 1, [0,1].swap ().unswap () [1]
// } // }
 End of changes. 7 change blocks. 
70 lines changed or deleted 87 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)