+ return mono("OK") //
+ .flatMapMany(Flux::just);
+ }
+
+ @Override
+ public Mono<String> getPolicyStatus(Policy policy) {
+ return mono("OK");
+ }
+
+ private <T> Mono<T> mono(T value) {
+ if (this.asynchDelay.isZero()) {
+ return Mono.just(value);
+ } else {
+ return Mono.create(monoSink -> asynchResponse(monoSink, value));
+ }
+ }
+
+ Mono<String> monoError(String responseBody, HttpStatus status) {
+ byte[] responseBodyBytes = responseBody.getBytes(StandardCharsets.UTF_8);
+ WebClientResponseException a1Exception = new WebClientResponseException(status.value(),
+ status.getReasonPhrase(), null, responseBodyBytes, StandardCharsets.UTF_8, null);
+ return Mono.error(a1Exception);
+ }
+
+ @SuppressWarnings("squid:S2925") // "Thread.sleep" should not be used in tests.
+ private void sleep() {
+ try {
+ Thread.sleep(this.asynchDelay.toMillis());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private <T> void asynchResponse(MonoSink<T> callback, T str) {
+ Thread thread = new Thread(() -> {
+ sleep(); // Simulate a network delay
+ callback.success(str);
+ });
+ thread.start();