Skip to content

Commit 7cafb14

Browse files
committed
test(feedback): Use @Narrative instead of javadoc
Also, some general test cleanup.
1 parent 79a83a7 commit 7cafb14

File tree

7 files changed

+153
-128
lines changed

7 files changed

+153
-128
lines changed

examples/app1/src/integration-test/groovy/grails/logical/delete/AnnotatedDataServiceSpec.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package grails.logical.delete
33
import app.PeopleDataService
44
import app.Person
55
import spock.lang.Specification
6+
import spock.lang.Title
67

78
import org.springframework.beans.factory.annotation.Autowired
89
import org.springframework.test.annotation.Rollback
@@ -11,13 +12,14 @@ import grails.logical.delete.test.PersonTestData
1112
import grails.testing.mixin.integration.Integration
1213

1314
@Integration
15+
@Title('Using @WithDeleted on Data Service methods')
1416
class AnnotatedDataServiceSpec extends Specification implements PersonTestData {
1517

1618
@Autowired
1719
PeopleDataService dataService
1820

1921
@Rollback
20-
void 'test method marked with @WithDeleted includes logically deleted results'() {
22+
void 'includes logically deleted results'() {
2123
when:
2224
List<Person> results = dataService.listPeople()
2325

examples/app1/src/integration-test/groovy/grails/logical/delete/CriteriaSpec.groovy

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
package grails.logical.delete
22

33
import app.Person
4-
import spock.lang.PendingFeature
4+
import spock.lang.Narrative
55
import spock.lang.Specification
6+
import spock.lang.Title
67

78
import grails.gorm.transactions.Rollback
89
import grails.logical.delete.test.PersonTestData
910
import grails.testing.mixin.integration.Integration
1011

11-
/**
12-
* This test suite focuses on the behavior of criteria API
13-
* in collaboration with the {@code PreQueryListener}.
14-
*/
1512
@Integration
13+
@Title('Using Criteria Queries')
14+
@Narrative('This specification focuses on the behavior of the Criteria API in collaboration with the PreQueryListener.')
1615
class CriteriaSpec extends Specification implements PersonTestData {
1716

1817
@Rollback
19-
/*
20-
@PendingFeature(
21-
reason = 'Currently PreQueryListener does not work with criteria queries'
22-
)
23-
*/
24-
void 'test criteria - logical deleted items'() {
18+
void 'logically deleted items are excluded from query results'() {
2519
given:
2620
assert Person.count() == 3
2721
Person.findByUserName('Ben').delete(flush: true)
@@ -53,7 +47,7 @@ class CriteriaSpec extends Specification implements PersonTestData {
5347
}
5448

5549
@Rollback
56-
void 'test criteria with projection - logical deleted items'() {
50+
void 'projection results exclude logically deleted items'() {
5751
given:
5852
assert Person.count() == 3
5953
Person.findByUserName('Ben').delete(flush: true)

examples/app1/src/integration-test/groovy/grails/logical/delete/DetachedCriteriaSpec.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package grails.logical.delete
22

33
import app.Person
44
import spock.lang.Specification
5+
import spock.lang.Title
56

67
import grails.gorm.transactions.Rollback
78
import grails.logical.delete.test.PersonTestData
@@ -12,10 +13,11 @@ import grails.testing.mixin.integration.Integration
1213
* in collaboration with the {@code PreQueryListener}.
1314
*/
1415
@Integration
16+
@Title('Using Detached Criteria Queries')
1517
class DetachedCriteriaSpec extends Specification implements PersonTestData {
1618

1719
@Rollback
18-
void 'test detached criteria where'() {
20+
void 'where query results exclude logically deleted items'() {
1921
given:
2022
assert Person.count() == 3
2123
Person.findByUserName('Ben').delete(flush: true)
@@ -42,7 +44,7 @@ class DetachedCriteriaSpec extends Specification implements PersonTestData {
4244
}
4345

4446
@Rollback
45-
void 'test detached criteria findAll'() {
47+
void 'findAll query results exclude logically deleted items'() {
4648
given:
4749
assert Person.count() == 3
4850
Person.findByUserName('Ben').delete(flush: true)

examples/app1/src/integration-test/groovy/grails/logical/delete/DynamicFindersSpec.groovy

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package grails.logical.delete
22

33
import app.Person
4+
import spock.lang.Narrative
45
import spock.lang.Specification
6+
import spock.lang.Title
57

68
import grails.gorm.transactions.Rollback
79
import grails.logical.delete.test.PersonTestData
810
import grails.testing.mixin.integration.Integration
911

10-
/**
11-
* This test suite focuses on the behavior of dynamic finders
12-
* in collaboration with the {@code PreQueryListener}.
13-
*/
1412
@Integration
13+
@Title('Using Dynamic Finders')
14+
@Narrative('This specification focuses on the behavior of dynamic finders in collaboration with the PreQueryListener.')
1515
class DynamicFindersSpec extends Specification implements PersonTestData {
1616

1717
@Rollback
18-
void 'test dynamic findAll hide logical deleted items'() {
18+
void 'findAll hide logical deleted items'() {
1919
// findAll() Call
2020
given:
2121
assert Person.count() == 3
@@ -39,7 +39,7 @@ class DynamicFindersSpec extends Specification implements PersonTestData {
3939
}
4040

4141
@Rollback
42-
void 'test dynamic findByUserName hide logical deleted items'() {
42+
void 'findByUserName hide logical deleted items'() {
4343
given:
4444
assert Person.count() == 3
4545
Person.findByUserName('Ben').delete(flush: true)
@@ -55,8 +55,7 @@ class DynamicFindersSpec extends Specification implements PersonTestData {
5555
}
5656

5757
@Rollback
58-
void 'test dynamic findByDeleted hide logical deleted items'() {
59-
// findByDeleted() Call
58+
void 'findByDeleted hide logical deleted items'() {
6059
given:
6160
assert Person.count() == 3
6261
Person.findByUserName('Ben').delete(flush: true)
@@ -78,7 +77,7 @@ class DynamicFindersSpec extends Specification implements PersonTestData {
7877
}
7978

8079
@Rollback
81-
void 'test dynamic get() finds logical deleted items'() {
80+
void 'get() hides logical deleted items'() {
8281
given:
8382
assert Person.count() == 3
8483
Person.findByUserName('Ben').delete(flush: true)
Lines changed: 80 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +1,185 @@
11
package grails.logical.delete
22

33
import app.Person
4+
import spock.lang.Narrative
45
import spock.lang.Specification
6+
import spock.lang.Title
57

68
import grails.gorm.transactions.Rollback
79
import grails.logical.delete.test.PersonTestData
810
import grails.testing.mixin.integration.Integration
911

10-
/**
11-
* This test suite focuses on how the deleted field in a LogicalDelete
12-
* implementation gets changed from overridden delete() operations.
13-
*/
1412
@Integration
13+
@Title('Verify LogicalDelete operations')
14+
@Narrative('This specification focuses on the behavior of the delete and undelete methods in the LogicalDelete implementation.')
1515
class LogicalDeleteSpec extends Specification implements PersonTestData {
1616

17-
/******************* delete tests - (w/ get) ***********************************/
18-
1917
@Rollback
20-
void 'test logical delete - get'() {
21-
when:
18+
void 'get(id) after logical delete works'() {
19+
20+
when: 'getting a non-deleted person'
2221
def p = Person.get(1)
2322

24-
then:
23+
then: 'person is not marked as deleted'
2524
!p.deleted
2625

27-
when:
26+
when: 'deleting the person logically'
2827
p.delete(flush: true)
2928
p = Person.withDeleted { Person.get(1) } as Person
3029

31-
then:
30+
then: 'person is marked as deleted'
3231
p.deleted
3332
}
3433

3534
@Rollback
36-
void 'test logical hard delete - get'() {
37-
when:
35+
void 'get(id) after hard delete works'() {
36+
37+
given: 'three persons in the database'
38+
assert Person.count() == 3
39+
40+
when: 'getting a non-deleted person'
3841
def p = Person.get(1)
3942

40-
then:
43+
then: 'the person is not marked as deleted'
4144
!p.deleted
4245

43-
when:
46+
when: 'deleting the person hard'
4447
p.delete(flush: true, hard: true)
48+
def count = Person.withDeleted { Person.count() }
4549

46-
then:
47-
Person.count() == 2 // 2 left after one hard deleted
50+
then: 'the person is removed from the database'
51+
count == 2
4852
}
4953

50-
/******************* delete tests - (w/ load) ***********************************/
51-
5254
@Rollback
53-
void 'test logical delete - load'() {
54-
when:
55+
void 'load(id) after logical delete works'() {
56+
57+
when: 'loading a non-deleted person'
5558
def p = Person.load(1)
5659

57-
then:
60+
then: 'the person is not marked as deleted'
5861
!p.deleted
5962

60-
when:
63+
when: 'deleting the person logically'
6164
p.delete(flush: true)
6265
p = Person.withDeleted { Person.load(1) } as Person
6366

64-
then:
67+
then: 'person is marked as deleted'
6568
p.deleted
6669
}
6770

6871
@Rollback
69-
void 'test logical hard delete - load'() {
70-
when:
72+
void 'load(id) after hard delete works'() {
73+
74+
given: 'three persons in the database'
75+
assert Person.count() == 3
76+
77+
when: 'loading a non-deleted person'
7178
def p = Person.load(1)
7279

73-
then:
80+
then: 'the person is not marked as deleted'
7481
!p.deleted
7582

76-
when:
83+
when: 'deleting the person hard'
7784
p.delete(flush: true, hard: true)
85+
def count = Person.withDeleted { Person.count() }
7886

79-
then:
80-
Person.count() == 2 // 2 left after one hard deleted
87+
then: 'the person is removed from the database'
88+
count == 2
8189
}
8290

83-
/******************* delete tests - (w/ proxy) ***********************************/
84-
8591
@Rollback
86-
void 'test logical delete - proxy'() {
87-
when:
92+
void 'proxy(id) after logical delete works'() {
93+
94+
when: 'getting a proxy for a non-deleted person'
8895
def p = Person.proxy(1)
8996

90-
then:
97+
then: 'the person is not marked as deleted'
9198
!p.deleted
9299

93-
when:
100+
when: 'deleting the person logically'
94101
p.delete(flush: true)
95102
p = Person.withDeleted { Person.proxy(1) } as Person
96103

97-
then:
104+
then: 'person is marked as deleted'
98105
p.deleted
99106
}
100107

101108
@Rollback
102-
void 'test logical hard delete - proxy'() {
103-
when:
109+
void 'proxy(id) after hard delete works'() {
110+
111+
given: 'three persons in the database'
112+
assert Person.count() == 3
113+
114+
when: 'getting a proxy for a non-deleted person'
104115
def p = Person.proxy(1)
105116

106-
then:
117+
then: 'the person is not marked as deleted'
107118
!p.deleted
108119

109-
when:
120+
when: 'deleting the person hard'
110121
p.delete(flush: true, hard: true)
122+
def count = Person.withDeleted { Person.count() }
111123

112-
then:
113-
Person.count() == 2 // 2 left after one hard deleted
124+
then: 'the person is removed from the database'
125+
count == 2 // 2 left after one hard deleted
114126
}
115127

116-
/******************* delete tests - (w/ read) ***********************************/
117-
118128
@Rollback
119-
void 'test logical delete - read'() {
120-
when:
129+
void 'read(id) after logical delete works'() {
130+
131+
when: 'reading a non-deleted person'
121132
def p = Person.read(1)
122133

123-
then:
134+
then: 'person is not marked as deleted'
124135
!p.deleted
125136

126-
when:
137+
when: 'deleting the person logically'
127138
p.delete(flush: true)
128139
p = Person.withDeleted { Person.read(1) } as Person
129140

130-
then:
141+
then: 'person is marked as deleted'
131142
p.deleted
132143
}
133144

134145
@Rollback
135-
void 'test logical hard delete - read'() {
136-
when:
146+
void 'read(id) after hard delete works'() {
147+
148+
given: 'three persons in the database'
149+
assert Person.count() == 3
150+
151+
when: 'reading a non-deleted person'
137152
def p = Person.read(1)
138153

139-
then:
154+
then: 'person is not marked as deleted'
140155
!p.deleted
141156

142-
when:
157+
when: 'deleting the person hard'
143158
p.delete(flush: true, hard: true)
159+
def count = Person.withDeleted { Person.count() }
144160

145-
then:
146-
Person.count() == 2 // 2 left after one hard deleted
161+
then: 'the person is removed from the database'
162+
count == 2
147163
}
148164

149-
/******************* undelete tests ***********************************/
150-
151165
@Rollback
152-
void 'test logical undelete'() {
153-
when:
166+
void 'undelete() works'() {
167+
168+
when: 'getting a non-deleted person'
154169
def p = Person.get(1)
170+
171+
and: 'deleting the person logically'
155172
p.delete(flush: true)
156173
p = Person.withDeleted { Person.get(1) } as Person
157174

158-
then:
175+
then: 'person is marked as deleted'
159176
p.deleted
160177

161-
when:
178+
when: 'undeleting the person'
162179
p.undelete(flush: true)
163180
p = Person.get(1)
164181

165-
then:
182+
then: 'person is no longer marked as deleted'
166183
!p.deleted
167184
}
168185
}

0 commit comments

Comments
 (0)