### Question:
MonoUtils { public <T> T unwrap(final Mono<T> mono) throws InterruptedException { try { return mono.block(); } catch (RuntimeException e) { if (e.getCause() instanceof InterruptedException) { throw (InterruptedException) e.getCause(); } throw e; } }  T unwrap(final Mono<T> mono); T unwrap(final Mono<T> mono, final Duration timeout);  }### Answer:
@Test @SneakyThrows @SuppressWarnings("unchecked") public void unwrapTest() { final Mono<String> mono = mock(Mono.class); when(mono.block()).thenReturn("OK"); assertEquals("OK", MonoUtils.unwrap(mono)); verify(mono).block(); verify(mono, never()).block(any()); }
@Test @SneakyThrows @SuppressWarnings("unchecked") public void unwrapTest_exception() { expectedException.expect(RuntimeException.class); final Mono<String> mono = mock(Mono.class); final Exception e = new RuntimeException(new Exception()); when(mono.block()).thenThrow(e); MonoUtils.unwrap(mono); }
@Test @SneakyThrows @SuppressWarnings("unchecked") public void unwrapTest_interruptedException() { expectedException.expect(InterruptedException.class); final Mono<String> mono = mock(Mono.class); final Exception e = new RuntimeException(new InterruptedException()); when(mono.block()).thenThrow(e); MonoUtils.unwrap(mono); }
@Test @SneakyThrows @SuppressWarnings("unchecked") public void unwrapTest_timeout() { final Mono<String> mono = mock(Mono.class); final Duration timeout = Duration.ofSeconds(1L); when(mono.block(timeout)).thenReturn("OK"); assertEquals("OK", MonoUtils.unwrap(mono, timeout)); verify(mono, never()).block(); verify(mono).block(timeout); }
@Test @SneakyThrows @SuppressWarnings("unchecked") public void unwrapTest_timeoutException() { expectedException.expect(RuntimeException.class); final Mono<String> mono = mock(Mono.class); final Duration timeout = Duration.ofSeconds(1L); final Exception e = new RuntimeException(new Exception()); when(mono.block(timeout)).thenThrow(e); MonoUtils.unwrap(mono, timeout); }
@Test @SneakyThrows @SuppressWarnings("unchecked") public void unwrapTest_timeoutInterruptedException() { expectedException.expect(InterruptedException.class); final Mono<String> mono = mock(Mono.class); final Duration timeout = Duration.ofSeconds(1L); final Exception e = new RuntimeException(new InterruptedException()); when(mono.block(timeout)).thenThrow(e); MonoUtils.unwrap(mono, timeout); }