Skip to content

Instantly share code, notes, and snippets.

@Test
void revoked() throws IOException {
get("https://revoked.sca1a.amazontrust.com/", urlConnection -> {
assertThatExceptionOfType(SSLHandshakeException.class)
.isThrownBy(urlConnection::getResponseCode)
.withRootCauseInstanceOf(CertificateRevokedException.class);
});
}
@codingtim
codingtim / ApiCallerTest.java
Last active November 18, 2018 14:44
Test for ApiCaller with MockWebServer
class ApiCallerTest {
private final MockWebServer mockWebServer = new MockWebServer();
private final ApiCaller apiCaller = new ApiCaller(WebClient.create(mockWebServer.url("/").toString()));
@AfterEach
void tearDown() throws IOException {
mockWebServer.shutdown();
}
@codingtim
codingtim / ApiCaller.java
Created November 18, 2018 14:25
WebClient calling an imaginary web api
class ApiCaller {
private WebClient webClient;
ApiCaller(WebClient webClient) {
this.webClient = webClient;
}
Mono<SimpleResponseDto> callApi() {
return webClient.put()
@codingtim
codingtim / UdpServer.kt
Created April 5, 2017 10:44
Simple udp server with netty 4.1 and kotlin
import io.netty.bootstrap.Bootstrap
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.SimpleChannelInboundHandler
import io.netty.channel.nio.NioEventLoopGroup
import io.netty.channel.socket.nio.NioDatagramChannel
import io.netty.util.CharsetUtil
import io.netty.util.concurrent.DefaultThreadFactory
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.newFixedThreadPoolContext
public class IteratorDataSourceConsumer {
private IteratorDataSource iteratorDataSource;
public void consume() {
iteratorDataSource.getAllEntities().forEachRemaining(entity -> {
//doStuff
});
}
}
public class IteratorDataSourceImpl implements IteratorDataSource {
private PagedDataSource pagedDataSource;
@Override
public Iterator<Entity> getAllEntities() {
return new PagedIterator(Paging.firstPage(), (Paging paging) -> pagedDataSource.getEntities(paging).iterator());
}
private static class PagedIterator implements Iterator<Entity> {
public interface IteratorDataSource {
Iterator<Entity> getAllEntities();
}
import com.mxgraph.canvas.mxICanvas;
import com.mxgraph.canvas.mxSvgCanvas;
import com.mxgraph.io.mxCodec;
import com.mxgraph.util.mxCellRenderer;
import com.mxgraph.util.mxDomUtils;
import com.mxgraph.util.mxUtils;
import com.mxgraph.util.mxXmlUtils;
import com.mxgraph.view.mxGraph;
public class DrawIoConverter{
public class PagedDataSourceConsumer {
private PagedDataSource pagedDataSource;
public void consume() {
List<Entity> entities;
Paging nextPage = Paging.firstPage();
for(entities = pagedDataSource.getEntities(nextPage); !entities.isEmpty(); entities = pagedDataSource.getEntities(nextPage)) {
for(Entity entity: entities) {
//doStuff
}
nextPage = nextPage.next();
public interface PagedDataSource {
List<Entity> getEntities(Paging paging);
}