Skip to content

Commit

Permalink
#72 Add test for ApiUsageStatisticsInterceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
magx2 committed May 29, 2020
1 parent fb69dfa commit 6ac7a1b
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ class ApiClientFactorySpec extends Specification {
.anyMatch { it == OneLineHttpLoggingInterceptor.class }
}

def "should add ApiUsageStatisticsInterceptor to interceptors"() {
given:
def token = "MTA1YzRhYWRiNzcyYTI0NzliNmMxZTM0MTkwNGM4NGYzYjY0YjBmZjBkYTUxZGVhNDg1NmYyODc1NDM3NDQxOA.aHR0cHM6Ly9zdnI0LnN1cGxhLm9yZw=="

when:
def client = ApiClientFactory.INSTANCE.newApiClient(token, Mock(ApiUsageStatisticsSetter.class))

then:
client.getHttpClient()
.interceptors()
.stream()
.map { it.getClass() }
.anyMatch { it == ApiUsageStatisticsInterceptor.class }
}

def "should not add ApiUsageStatisticsInterceptor to interceptors"() {
given:
def token = "MTA1YzRhYWRiNzcyYTI0NzliNmMxZTM0MTkwNGM4NGYzYjY0YjBmZjBkYTUxZGVhNDg1NmYyODc1NDM3NDQxOA.aHR0cHM6Ly9zdnI0LnN1cGxhLm9yZw=="

when:
def client = ApiClientFactory.INSTANCE.newApiClient(token, (ApiUsageStatisticsSetter) null)

then:
!client.getHttpClient()
.interceptors()
.stream()
.map { it.getClass() }
.anyMatch { it == ApiUsageStatisticsInterceptor.class }
}

def "should set proper base path"() {
given:
def token = "MTA1YzRhYWRiNzcyYTI0NzliNmMxZTM0MTkwNGM4NGYzYjY0YjBmZjBkYTUxZGVhNDg1NmYyODc1NDM3NDQxOA.aHR0cHM6Ly9zdnI0LnN1cGxhLm9yZw=="
Expand Down

0 comments on commit 6ac7a1b

Please sign in to comment.