01: /*******************************************************************************
02: * Portions created by Sebastian Thomschke are copyright (c) 2005-2007 Sebastian
03: * Thomschke.
04: *
05: * All Rights Reserved. This program and the accompanying materials
06: * are made available under the terms of the Eclipse Public License v1.0
07: * which accompanies this distribution, and is available at
08: * http://www.eclipse.org/legal/epl-v10.html
09: *
10: * Contributors:
11: * Sebastian Thomschke - initial implementation.
12: *******************************************************************************/package net.sf.oval.test.guard;
13:
14: import junit.framework.TestCase;
15: import net.sf.oval.constraint.AssertFieldConstraints;
16: import net.sf.oval.constraint.NotNull;
17: import net.sf.oval.exception.ConstraintsViolatedException;
18: import net.sf.oval.guard.Guard;
19: import net.sf.oval.guard.Guarded;
20:
21: /**
22: * @author Sebastian Thomschke
23: */
24: public class InheritanceTest extends TestCase {
25: @Guarded(applyFieldConstraintsToSetters=true)
26: public static class SuperEntity {
27: @NotNull
28: protected String name = "";
29:
30: /**
31: * @return the name
32: */
33: public String getName() {
34: return name;
35: }
36:
37: /**
38: * @param name the name to set
39: */
40: public void setName(String name) {
41: this .name = name;
42: }
43: }
44:
45: @Guarded
46: public static class Entity extends SuperEntity {
47: /**
48: * @param name the name to set
49: */
50: public void setName2(@AssertFieldConstraints
51: String name) {
52: this .name = name;
53: }
54: }
55:
56: public void testInheritance() {
57: final Guard guard = new Guard();
58: TestGuardAspect.aspectOf().setGuard(guard);
59:
60: Entity e = new Entity();
61:
62: try {
63: e.setName(null);
64: fail("ConstraintViolationException should have been thrown");
65: } catch (ConstraintsViolatedException ex) {
66: // expected
67: }
68:
69: try {
70: e.setName2(null);
71: fail("ConstraintViolationException should have been thrown");
72: } catch (ConstraintsViolatedException ex) {
73: // expected
74: }
75: }
76: }
|