-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c442583
commit 9eaf1f6
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/test/groovy/grails/plugin/cache/CustomCacheKeyGeneratorSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package grails.plugin.cache | ||
|
||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class CustomCacheKeyGeneratorSpec extends Specification { | ||
|
||
void 'test matching keys'() { | ||
|
||
given: | ||
CustomCacheKeyGenerator keyGenerator = new CustomCacheKeyGenerator() | ||
|
||
when: | ||
Serializable key1 = keyGenerator.generate('TestService', 'method', 0, [ arg1: 1, arg2: 2 ]) | ||
Serializable key2 = keyGenerator.generate('TestService', 'method', 0, [ arg1: 1, arg2: 2 ]) | ||
|
||
then: | ||
key1.hashCode() == key2.hashCode() | ||
} | ||
|
||
@Unroll('#className::#methodName(#params) should not match TestService::method([arg1: 1, arg2: 2])') | ||
void 'test differing keys'() { | ||
|
||
given: | ||
CustomCacheKeyGenerator keyGenerator = new CustomCacheKeyGenerator() | ||
Serializable key1 = keyGenerator.generate('TestService', 'method', 0, [ arg1: 1, arg2: 2 ]) | ||
|
||
when: | ||
Serializable key2 = keyGenerator.generate(className, methodName, 0, params) | ||
|
||
then: | ||
key1.hashCode() != key2.hashCode() | ||
|
||
where: | ||
className | methodName | params | ||
'TestService' | 'method' | [ arg1: 1, arg2: 3 ] | ||
'TestService' | 'method' | [ arg1: 1, _arg2: 2 ] | ||
'TestService' | '_method' | [ arg1: 1, arg2: 2 ] | ||
'_TestService' | 'method' | [ arg1: 1, arg2: 2 ] | ||
} | ||
} |