Skip to content

Commit 244c961

Browse files
committed
added consistent license header
1 parent 9229846 commit 244c961

File tree

7 files changed

+413
-325
lines changed

7 files changed

+413
-325
lines changed

org.springframework.aspects/src/main/java/org/springframework/mock/staticmock/AbstractMethodMockingControl.aj

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2002-2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package org.springframework.mock.staticmock;
218

319
import java.util.Arrays;
@@ -12,7 +28,6 @@ import java.util.List;
1228
*
1329
* @author Rod Johnson
1430
* @author Ramnivas Laddad
15-
*
1631
*/
1732
public abstract aspect AbstractMethodMockingControl percflow(mockStaticsTestMethod()) {
1833

org.springframework.aspects/src/main/java/org/springframework/mock/staticmock/AnnotationDrivenStaticEntityMockingControl.aj

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
package org.springframework.mock.staticmock;
1+
/*
2+
* Copyright 2002-2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216

3-
import javax.persistence.Entity;
17+
package org.springframework.mock.staticmock;
418

519
/**
620
* Annotation-based aspect to use in test build to enable mocking static methods
@@ -23,11 +37,9 @@ import javax.persistence.Entity;
2337
* occur automatically.
2438
* </ol>
2539
*
26-
* @see MockStaticEntityMethods
27-
*
2840
* @author Rod Johnson
2941
* @author Ramnivas Laddad
30-
*
42+
* @see MockStaticEntityMethods
3143
*/
3244
public aspect AnnotationDrivenStaticEntityMockingControl extends AbstractMethodMockingControl {
3345

@@ -50,6 +62,6 @@ public aspect AnnotationDrivenStaticEntityMockingControl extends AbstractMethodM
5062
// @MockStatics classes to invoke each other without resetting the mocking environment
5163
protected pointcut mockStaticsTestMethod() : execution(public * (@MockStaticEntityMethods *).*(..));
5264

53-
protected pointcut methodToMock() : execution(public static * (@Entity *).*(..));
65+
protected pointcut methodToMock() : execution(public static * (@javax.persistence.Entity *).*(..));
5466

5567
}

org.springframework.aspects/src/main/java/org/springframework/mock/staticmock/MockStaticEntityMethods.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2002-2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.springframework.mock.staticmock;
217

318
import java.lang.annotation.ElementType;
@@ -8,11 +23,9 @@
823
/**
924
* Annotation to indicate a test class for whose @Test methods
1025
* static methods on Entity classes should be mocked.
11-
*
12-
* @see AbstractMethodMockingControl
13-
*
14-
* @author Rod Johnson
1526
*
27+
* @author Rod Johnson
28+
* @see AbstractMethodMockingControl
1629
*/
1730
@Retention(RetentionPolicy.RUNTIME)
1831
@Target(ElementType.TYPE)
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,146 @@
1-
/*
2-
* Copyright 2009 SpringSource Inc.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
17-
package org.springframework.mock.staticmock;
18-
19-
import javax.persistence.PersistenceException;
20-
21-
import junit.framework.Assert;
22-
23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
25-
import org.junit.runners.JUnit4;
26-
27-
import static org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.*;
28-
29-
30-
/**
31-
* Test for static entity mocking framework.
32-
* @author Rod Johnson
33-
* @author Ramnivas Laddad
34-
*
35-
*/
36-
@MockStaticEntityMethods
37-
@RunWith(JUnit4.class)
38-
public class AnnotationDrivenStaticEntityMockingControlTest {
39-
40-
@Test
41-
public void testNoArgIntReturn() {
42-
int expectedCount = 13;
43-
Person.countPeople();
44-
expectReturn(expectedCount);
45-
playback();
46-
Assert.assertEquals(expectedCount, Person.countPeople());
47-
}
48-
49-
@Test(expected=PersistenceException.class)
50-
public void testNoArgThrows() {
51-
Person.countPeople();
52-
expectThrow(new PersistenceException());
53-
playback();
54-
Person.countPeople();
55-
}
56-
57-
@Test
58-
public void testArgMethodMatches() {
59-
long id = 13;
60-
Person found = new Person();
61-
Person.findPerson(id);
62-
expectReturn(found);
63-
playback();
64-
Assert.assertEquals(found, Person.findPerson(id));
65-
}
66-
67-
68-
@Test
69-
public void testLongSeriesOfCalls() {
70-
long id1 = 13;
71-
long id2 = 24;
72-
Person found1 = new Person();
73-
Person.findPerson(id1);
74-
expectReturn(found1);
75-
Person found2 = new Person();
76-
Person.findPerson(id2);
77-
expectReturn(found2);
78-
Person.findPerson(id1);
79-
expectReturn(found1);
80-
Person.countPeople();
81-
expectReturn(0);
82-
playback();
83-
84-
Assert.assertEquals(found1, Person.findPerson(id1));
85-
Assert.assertEquals(found2, Person.findPerson(id2));
86-
Assert.assertEquals(found1, Person.findPerson(id1));
87-
Assert.assertEquals(0, Person.countPeople());
88-
}
89-
90-
// Note delegation is used when tests are invalid and should fail, as otherwise
91-
// the failure will occur on the verify() method in the aspect after
92-
// this method returns, failing the test case
93-
@Test
94-
public void testArgMethodNoMatchExpectReturn() {
95-
try {
96-
new Delegate().testArgMethodNoMatchExpectReturn();
97-
Assert.fail();
98-
} catch (IllegalArgumentException expected) {
99-
}
100-
}
101-
102-
@Test(expected=IllegalArgumentException.class)
103-
public void testArgMethodNoMatchExpectThrow() {
104-
new Delegate().testArgMethodNoMatchExpectThrow();
105-
}
106-
107-
private void called(Person found, long id) {
108-
Assert.assertEquals(found, Person.findPerson(id));
109-
}
110-
111-
@Test
112-
public void testReentrant() {
113-
long id = 13;
114-
Person found = new Person();
115-
Person.findPerson(id);
116-
expectReturn(found);
117-
playback();
118-
called(found, id);
119-
}
120-
121-
@Test(expected=IllegalStateException.class)
122-
public void testRejectUnexpectedCall() {
123-
new Delegate().rejectUnexpectedCall();
124-
}
125-
126-
@Test(expected=IllegalStateException.class)
127-
public void testFailTooFewCalls() {
128-
new Delegate().failTooFewCalls();
129-
}
130-
131-
@Test
132-
public void testEmpty() {
133-
// Test that verification check doesn't blow up if no replay() call happened
134-
}
135-
136-
@Test(expected=IllegalStateException.class)
137-
public void testDoesntEverReplay() {
138-
new Delegate().doesntEverReplay();
139-
}
140-
141-
@Test(expected=IllegalStateException.class)
142-
public void testDoesntEverSetReturn() {
143-
new Delegate().doesntEverSetReturn();
144-
}
145-
}
146-
1+
/*
2+
* Copyright 2002-2010 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.mock.staticmock;
18+
19+
import javax.persistence.PersistenceException;
20+
21+
import junit.framework.Assert;
22+
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.junit.runners.JUnit4;
26+
27+
import static org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.*;
28+
29+
30+
/**
31+
* Test for static entity mocking framework.
32+
* @author Rod Johnson
33+
* @author Ramnivas Laddad
34+
*
35+
*/
36+
@MockStaticEntityMethods
37+
@RunWith(JUnit4.class)
38+
public class AnnotationDrivenStaticEntityMockingControlTest {
39+
40+
@Test
41+
public void testNoArgIntReturn() {
42+
int expectedCount = 13;
43+
Person.countPeople();
44+
expectReturn(expectedCount);
45+
playback();
46+
Assert.assertEquals(expectedCount, Person.countPeople());
47+
}
48+
49+
@Test(expected=PersistenceException.class)
50+
public void testNoArgThrows() {
51+
Person.countPeople();
52+
expectThrow(new PersistenceException());
53+
playback();
54+
Person.countPeople();
55+
}
56+
57+
@Test
58+
public void testArgMethodMatches() {
59+
long id = 13;
60+
Person found = new Person();
61+
Person.findPerson(id);
62+
expectReturn(found);
63+
playback();
64+
Assert.assertEquals(found, Person.findPerson(id));
65+
}
66+
67+
68+
@Test
69+
public void testLongSeriesOfCalls() {
70+
long id1 = 13;
71+
long id2 = 24;
72+
Person found1 = new Person();
73+
Person.findPerson(id1);
74+
expectReturn(found1);
75+
Person found2 = new Person();
76+
Person.findPerson(id2);
77+
expectReturn(found2);
78+
Person.findPerson(id1);
79+
expectReturn(found1);
80+
Person.countPeople();
81+
expectReturn(0);
82+
playback();
83+
84+
Assert.assertEquals(found1, Person.findPerson(id1));
85+
Assert.assertEquals(found2, Person.findPerson(id2));
86+
Assert.assertEquals(found1, Person.findPerson(id1));
87+
Assert.assertEquals(0, Person.countPeople());
88+
}
89+
90+
// Note delegation is used when tests are invalid and should fail, as otherwise
91+
// the failure will occur on the verify() method in the aspect after
92+
// this method returns, failing the test case
93+
@Test
94+
public void testArgMethodNoMatchExpectReturn() {
95+
try {
96+
new Delegate().testArgMethodNoMatchExpectReturn();
97+
Assert.fail();
98+
} catch (IllegalArgumentException expected) {
99+
}
100+
}
101+
102+
@Test(expected=IllegalArgumentException.class)
103+
public void testArgMethodNoMatchExpectThrow() {
104+
new Delegate().testArgMethodNoMatchExpectThrow();
105+
}
106+
107+
private void called(Person found, long id) {
108+
Assert.assertEquals(found, Person.findPerson(id));
109+
}
110+
111+
@Test
112+
public void testReentrant() {
113+
long id = 13;
114+
Person found = new Person();
115+
Person.findPerson(id);
116+
expectReturn(found);
117+
playback();
118+
called(found, id);
119+
}
120+
121+
@Test(expected=IllegalStateException.class)
122+
public void testRejectUnexpectedCall() {
123+
new Delegate().rejectUnexpectedCall();
124+
}
125+
126+
@Test(expected=IllegalStateException.class)
127+
public void testFailTooFewCalls() {
128+
new Delegate().failTooFewCalls();
129+
}
130+
131+
@Test
132+
public void testEmpty() {
133+
// Test that verification check doesn't blow up if no replay() call happened
134+
}
135+
136+
@Test(expected=IllegalStateException.class)
137+
public void testDoesntEverReplay() {
138+
new Delegate().doesntEverReplay();
139+
}
140+
141+
@Test(expected=IllegalStateException.class)
142+
public void testDoesntEverSetReturn() {
143+
new Delegate().doesntEverSetReturn();
144+
}
145+
}
146+

0 commit comments

Comments
 (0)