Skip to content

Commit

Permalink
added static factory methods to interceptors
Browse files Browse the repository at this point in the history
  • Loading branch information
Joaquimmnetto committed Jul 7, 2021
1 parent e9a74a6 commit 299c6fe
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package com.wooga.spock.extensions.github
import com.wooga.spock.extensions.github.interceptor.FieldInterceptor
import com.wooga.spock.extensions.github.interceptor.GithubRepositoryFeatureInterceptor
import com.wooga.spock.extensions.github.interceptor.GithubRepositoryInterceptor
import com.wooga.spock.extensions.github.interceptor.RepositoryFieldOperations
import com.wooga.spock.extensions.github.interceptor.SharedGithubRepositoryInterceptor
import org.spockframework.runtime.extension.AbstractAnnotationDrivenExtension
import org.spockframework.runtime.model.FeatureInfo
Expand All @@ -31,18 +30,15 @@ class GithubRepositoryExtension extends AbstractAnnotationDrivenExtension<Github

@Override
void visitFeatureAnnotation(GithubRepository annotation, FeatureInfo feature) {
def repoFactory = new RepositoryFactory(annotation)
def interceptor = new GithubRepositoryFeatureInterceptor(annotation, repoFactory)
def interceptor = GithubRepositoryFeatureInterceptor.withMetadata(annotation)
interceptor.install(feature)
}

@Override
void visitFieldAnnotation(GithubRepository annotation, FieldInfo field) {
def repoFactory = new RepositoryFactory(annotation)
def repoOps = new RepositoryFieldOperations(field, repoFactory)
FieldInterceptor interceptor = field.isShared()?
new SharedGithubRepositoryInterceptor(annotation, repoOps) :
new GithubRepositoryInterceptor(repoOps)
SharedGithubRepositoryInterceptor.withMetadata(annotation, field) :
GithubRepositoryInterceptor.withMetadata(annotation, field)

interceptor.install(field)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import org.spockframework.runtime.model.FieldInfo

interface FieldInterceptor {
void install(FieldInfo info)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ class GithubRepositoryFeatureInterceptor extends AbstractMethodInterceptor {
private GithubRepository metadata
Repository repo;

static GithubRepositoryFeatureInterceptor withMetadata(GithubRepository metadata) {
def repoFactory = new RepositoryFactory(metadata)
return new GithubRepositoryFeatureInterceptor(metadata, repoFactory)
}

GithubRepositoryFeatureInterceptor(GithubRepository metadata, RepositoryFactory factory) {
this.metadata = metadata
this.factory = factory
Expand Down Expand Up @@ -116,4 +121,4 @@ class GithubRepositoryFeatureInterceptor extends AbstractMethodInterceptor {
repo.captureResetRefs()
return repo
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

package com.wooga.spock.extensions.github.interceptor


import com.wooga.spock.extensions.github.GithubRepository
import com.wooga.spock.extensions.github.RepositoryFactory
import groovy.transform.InheritConstructors
import org.spockframework.runtime.extension.AbstractMethodInterceptor
import org.spockframework.runtime.extension.IMethodInvocation
Expand All @@ -28,6 +29,12 @@ class GithubRepositoryInterceptor extends AbstractMethodInterceptor implements F

private RepositoryFieldOperations ops;

static GithubRepositoryInterceptor withMetadata(GithubRepository metadata, FieldInfo field) {
def repoFactory = new RepositoryFactory(metadata)
def repoOps = new RepositoryFieldOperations(field, repoFactory)
return new GithubRepositoryInterceptor(repoOps)
}

GithubRepositoryInterceptor(RepositoryFieldOperations ops) {
this.ops = ops
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.wooga.spock.extensions.github.interceptor

import com.wooga.spock.extensions.github.GithubRepository
import com.wooga.spock.extensions.github.RepositoryFactory
import groovy.transform.InheritConstructors
import org.spockframework.runtime.extension.AbstractMethodInterceptor
import org.spockframework.runtime.extension.IMethodInvocation
Expand All @@ -29,6 +30,12 @@ class SharedGithubRepositoryInterceptor extends AbstractMethodInterceptor implem
GithubRepository metadata;
RepositoryFieldOperations ops;

static SharedGithubRepositoryInterceptor withMetadata(GithubRepository metadata, FieldInfo field) {
def repoFactory = new RepositoryFactory(metadata)
def repoOps = new RepositoryFieldOperations(field, repoFactory)
return new SharedGithubRepositoryInterceptor(metadata, repoOps)
}

SharedGithubRepositoryInterceptor(GithubRepository metadata, RepositoryFieldOperations ops) {
this.metadata = metadata
this.ops = ops
Expand Down

0 comments on commit 299c6fe

Please sign in to comment.