Skip to content

Commit

Permalink
Add unit test which registers cache manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Scott Brown committed Jul 19, 2016
1 parent 4d03718 commit d5a1f49
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.demo

import grails.test.mixin.TestFor
import spock.lang.Specification

@TestFor(BasicCachingService)
class BasicCachingServiceNoCacheManagerSpec extends Specification {

void 'test invoking cacheable method when no cache manager is present'() {
when:
def result = service.getData()

then:
result == 'Hello World!'
service.invocationCounter == 1

when:
result = service.getData()

then:
result == 'Hello World!'
service.invocationCounter == 2
}
}
13 changes: 11 additions & 2 deletions src/test/groovy/com/demo/BasicCachingServiceSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.demo

import grails.plugin.cache.CustomCacheKeyGenerator
import grails.plugin.cache.GrailsConcurrentMapCacheManager
import grails.test.mixin.TestFor
import spock.lang.Specification

@TestFor(BasicCachingService)
class BasicCachingServiceSpec extends Specification {

void 'test invoking cacheable method when no cache manager is present'() {
static doWithSpring = {
// TODO The plugin should provide a convenient
// mechanism for setting these up...
grailsCacheManager(GrailsConcurrentMapCacheManager)
customCacheKeyGenerator(CustomCacheKeyGenerator)
}

void 'test invoking cacheable method when cache manager is present'() {
when:
def result = service.getData()

Expand All @@ -19,6 +28,6 @@ class BasicCachingServiceSpec extends Specification {

then:
result == 'Hello World!'
service.invocationCounter == 2
service.invocationCounter == 1
}
}

0 comments on commit d5a1f49

Please sign in to comment.