TedeeLockGateway.java

1
package org.sanmibuh.tedee.lock.infrastructure.secondary;
2
3
import com.tedee.bridge.client.api.LockApi;
4
import lombok.RequiredArgsConstructor;
5
import org.sanmibuh.tedee.lock.domain.exception.InvalidLockRequestException;
6
import org.sanmibuh.tedee.lock.domain.exception.LockOperationFailedException;
7
import org.sanmibuh.tedee.lock.domain.exception.LockTemporarilyUnavailableException;
8
import org.sanmibuh.tedee.lock.domain.vo.LockId;
9
import org.springframework.http.HttpStatus;
10
import org.springframework.stereotype.Component;
11
import org.springframework.web.client.RestClientException;
12
import org.springframework.web.client.RestClientResponseException;
13
14
@Component
15
@RequiredArgsConstructor
16
final class TedeeLockGateway implements LockGateway {
17
18
  private final LockApi lockApi;
19
20
  @Override
21
  public void lock(final LockId lockId) {
22
    final var deviceId = lockId.value();
23
    try {
24 1 1. lock : removed call to com/tedee/bridge/client/api/LockApi::postLock → KILLED
      lockApi.postLock(deviceId);
25
    } catch (final RestClientResponseException exception) {
26
      throw translateException(exception, deviceId);
27
    } catch (final RestClientException exception) {
28
      throw new LockTemporarilyUnavailableException(deviceId, exception);
29
    }
30
  }
31
32
  private RuntimeException translateException(
33
      final RestClientResponseException exception, final int deviceId) {
34 1 1. translateException : replaced return value with null for org/sanmibuh/tedee/lock/infrastructure/secondary/TedeeLockGateway::translateException → KILLED
    return switch (HttpStatus.resolve(exception.getStatusCode().value())) {
35
      case NOT_FOUND -> new InvalidLockRequestException(deviceId, exception);
36
      case METHOD_NOT_ALLOWED,
37
          NOT_ACCEPTABLE,
38
          CONFLICT,
39
          BAD_GATEWAY,
40
          SERVICE_UNAVAILABLE,
41
          GATEWAY_TIMEOUT ->
42
          new LockTemporarilyUnavailableException(deviceId, exception);
43
      case null, default -> new LockOperationFailedException(deviceId, exception);
44
    };
45
  }
46
}

Mutations

24

1.1
Location : lock
Killed by : org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeLockGatewayTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeLockGatewayTest]/[method:should_postToLockEndpoint_whenLocking()]
removed call to com/tedee/bridge/client/api/LockApi::postLock → KILLED

34

1.1
Location : translateException
Killed by : org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeLockGatewayTest.[engine:junit-jupiter]/[class:org.sanmibuh.tedee.lock.infrastructure.secondary.TedeeLockGatewayTest]/[test-template:should_translateWithoutRetrying_whenBridgeRespondsWithNonTransientError(org.springframework.http.HttpStatus, java.lang.Class)]/[test-template-invocation:#2]
replaced return value with null for org/sanmibuh/tedee/lock/infrastructure/secondary/TedeeLockGateway::translateException → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support