"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/test/groovy/lang/InterceptorTest.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.

InterceptorTest.groovy  (apache-groovy-src-3.0.8):InterceptorTest.groovy  (apache-groovy-src-3.0.9)
skipping to change at line 26 skipping to change at line 26
* 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.GroovyTestCase import groovy.test.GroovyTestCase
import org.codehaus.groovy.runtime.StringBufferWriter import org.codehaus.groovy.runtime.StringBufferWriter
/** /**
* Test for the Interceptor Interface usage as implemented by the * Test for the Interceptor Interface usage as implemented by the
* TracingInterceptor. Makes also use of the ProxyMetaClass and * {@link TracingInterceptor}. Makes use of the {@link ProxyMetaClass} and
* shows the collaboration. * shows the collaboration.
* As a side Effect, the ProxyMetaClass is also partly tested. * <p>
* As a side effect, the {@code ProxyMetaClass} is also partly tested.
*/ */
class InterceptorTest extends GroovyTestCase { final class InterceptorTest extends GroovyTestCase {
def Interceptor logInterceptor private final Interceptor interceptor = new TracingInterceptor() // class un
def StringBuffer log der test
def interceptable // the object to intercept method calls on private final String interceptable = 'Interceptable String' // the object to
def proxy observe
private final ProxyMetaClass proxy = ProxyMetaClass.getInstance(interceptabl
e.class)
private final StringBuffer log = new StringBuffer('\n')
void setUp() { void setUp() {
logInterceptor = new TracingInterceptor() interceptor.writer = new StringBufferWriter(log)
log = new StringBuffer("\n") proxy.interceptor = interceptor
logInterceptor.writer = new StringBufferWriter(log)
// we intercept calls from Groovy to the java.lang.String object
interceptable = 'Interceptable String'
proxy = ProxyMetaClass.getInstance(interceptable.class)
proxy.setInterceptor(logInterceptor)
} }
void testSimpleInterception() { void testSimpleInterception() {
proxy.use { proxy.use {
assertEquals 20, interceptable.size() assertEquals 20, interceptable.size()
assertEquals 20, interceptable.length() assertEquals 20, interceptable.length()
assertTrue interceptable.startsWith('I', 0) assertTrue interceptable.startsWith('I', 0)
} }
assertEquals(""" assertEquals("""
before java.lang.String.size() before java.lang.String.size()
skipping to change at line 93 skipping to change at line 89
} }
assertEquals(""" assertEquals("""
before java.lang.String.valueOf(java.lang.Boolean) before java.lang.String.valueOf(java.lang.Boolean)
after java.lang.String.valueOf(java.lang.Boolean) after java.lang.String.valueOf(java.lang.Boolean)
""", log.toString()) """, log.toString())
} }
void testInterceptionOfGroovyClasses() { void testInterceptionOfGroovyClasses() {
def slicer = new groovy.mock.example.CheeseSlicer() def slicer = new groovy.mock.example.CheeseSlicer()
def proxy = ProxyMetaClass.getInstance(slicer.class) def proxy = ProxyMetaClass.getInstance(slicer.class)
proxy.setInterceptor(logInterceptor) proxy.setInterceptor(interceptor)
proxy.use(slicer) { proxy.use(slicer) {
slicer.coffeeBreak('') slicer.coffeeBreak('')
} }
assertEquals(""" assertEquals("""
before groovy.mock.example.CheeseSlicer.coffeeBreak(java.lang.String) before groovy.mock.example.CheeseSlicer.coffeeBreak(java.lang.String)
after groovy.mock.example.CheeseSlicer.coffeeBreak(java.lang.String) after groovy.mock.example.CheeseSlicer.coffeeBreak(java.lang.String)
""", log.toString()) """, log.toString())
} }
void testProxyMetaClassUseMethodShouldReturnTheResultOfClosure() { void testProxyMetaClassUseMethodShouldReturnTheResultOfClosure() {
assertEquals true, proxy.use { true } assertTrue proxy.use { true }
}
// GROOVY-10009
void testNullArgumentToMethodCall() {
interceptable.metaClass = proxy
interceptable.equals(null)
assertEquals '''
|before java.lang.String.equals(java.lang.Object)
|after java.lang.String.equals(java.lang.Object)
|'''.stripMargin(), log.toString()
} }
} }
 End of changes. 7 change blocks. 
16 lines changed or deleted 26 lines changed or added

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