Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
added test-case for @AnnotationContract on post-conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
andresteingress committed Mar 31, 2011
1 parent 51a6f45 commit 2d39ac5
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.junit.Test
import static junit.framework.Assert.assertNotNull
import static junit.framework.Assert.fail
import org.gcontracts.PreconditionViolation
import org.gcontracts.PostconditionViolation

/**
* @author ast
Expand Down Expand Up @@ -48,6 +49,41 @@ class AnnotationContractTests {
tester.method(null)
}

@Test(expected = PostconditionViolation.class)
void single_notnull_parameter_postcondition() {

def source_anno_parameter = '''
package tests
import org.gcontracts.annotations.*
import org.gcontracts.annotations.meta.*
import java.lang.annotation.*
@Postcondition
@AnnotationContract({ it != null })
public @interface NotNull {}
'''
def source_parameter = '''
@Contracted
package tests
import org.gcontracts.annotations.*
class Tester {
def method(@NotNull param) { println "test" }
}'''

GroovyClassLoader loader = new GroovyClassLoader(getClass().getClassLoader())
loader.parseClass(source_anno_parameter)
Class clz = loader.parseClass(source_parameter)
assertNotNull(clz)

def tester = clz.newInstance()

tester.method(null)
}

@Test(expected = PreconditionViolation.class)
void multiple_notnull_parameters() {

Expand Down

0 comments on commit 2d39ac5

Please sign in to comment.