@Override
    protected ActivityState<TransportProtos.SessionInfoProto> updateState(UUID sessionId, ActivityState<TransportProtos.SessionInfoProto> state) {
        SessionMetaData session = sessions.get(sessionId);
        if (session == null) {
            return null;
        }

        state.setMetadata(session.getSessionInfo());
        var sessionInfo = state.getMetadata();

        if (sessionInfo.getGwSessionIdMSB() == 0L || sessionInfo.getGwSessionIdLSB() == 0L) {
            return state;
        }

        var gwSessionId = new UUID(sessionInfo.getGwSessionIdMSB(), sessionInfo.getGwSessionIdLSB());
        SessionMetaData gwSession = sessions.get(gwSessionId);
        if (gwSession == null || !gwSession.isOverwriteActivityTime()) {
            return state;
        }

        long lastRecordedTime = state.getLastRecordedTime();
        long gwLastRecordedTime = getLastRecordedTime(gwSessionId);
        log.debug("Session with id: [{}] has gateway session with id: [{}] with overwrite activity time enabled. " +
                        "Updating last activity time. Session last recorded time: [{}], gateway session last recorded time: [{}].",
                sessionId, gwSessionId, lastRecordedTime, gwLastRecordedTime);
        state.setLastRecordedTime(Math.max(lastRecordedTime, gwLastRecordedTime));
        return state;
    }
@Test
    void givenSessionDoesNotExist_whenUpdatingActivityState_thenShouldReturnNull() {
        // GIVEN
        TransportProtos.SessionInfoProto sessionInfo = TransportProtos.SessionInfoProto.newBuilder()
                .setSessionIdMSB(SESSION_ID.getMostSignificantBits())
                .setSessionIdLSB(SESSION_ID.getLeastSignificantBits())
                .build();

        ActivityState<TransportProtos.SessionInfoProto> state = new ActivityState<>();
        state.setLastRecordedTime(123L);
        state.setMetadata(sessionInfo);

        when(transportServiceMock.updateState(SESSION_ID, state)).thenCallRealMethod();

        // WHEN
        ActivityState<TransportProtos.SessionInfoProto> updatedState = transportServiceMock.updateState(SESSION_ID, state);

        // THEN
        assertThat(updatedState).isNull();
    }