Skip to content

Instantly share code, notes, and snippets.

View swankjesse's full-sized avatar
🍩
busy busy

Jesse Wilson swankjesse

🍩
busy busy
View GitHub Profile
import com.google.mockwebserver.Dispatcher;
import com.google.mockwebserver.MockResponse;
import com.google.mockwebserver.MockWebServer;
import com.google.mockwebserver.RecordedRequest;
import java.io.IOException;
import java.net.HttpURLConnection;
public class Redirector {
public static void main(String[] args) throws IOException {
MockWebServer server = new MockWebServer();
@swankjesse
swankjesse / Rip.java
Created February 8, 2013 23:27
Stream editor for Java nerds. Use Java regular expressions to break up lines, and Java format strings to put them back together again.
/*bin/mkdir /tmp/rip 2> /dev/null
javac -d /tmp/rip $0
java -cp /tmp/rip Rip "$@"
exit
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.regex.Matcher;
package p1;
public class A {
void foo() {
System.out.println("A.foo");
}
public void aFoo() {
foo();
}
}
@swankjesse
swankjesse / MockingAndClassLoadersTest.java
Created March 2, 2013 14:14
Test that shows that how package-private methods are dispatched depends on class loading.
package org.mockitousage.packageprotected;
import org.junit.Test;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import org.mockitoutil.ClassLoaderBuilder;
import org.mockitoutil.TestBase;
public class MockingAndClassLoadersTest extends TestBase {
@swankjesse
swankjesse / gist:5391810
Created April 15, 2013 22:28
PutDuringRemoveEldestEntryTest.java
import java.util.LinkedHashMap;
import java.util.Map;
import junit.framework.TestCase;
public class PutDuringRemoveEldestEntryTest extends TestCase {
public void test() {
Map<String, String> map = new LinkedHashMap<String, String>(4) {
@Override protected boolean removeEldestEntry(Map.Entry<String, String> eldest) {
if (size() == 4) {
super.put("a", "a"); // This will trigger doubleCapacity().
@swankjesse
swankjesse / RetrofitCachingExample.java
Created June 29, 2013 03:03
Demonstrate HTTP caching with OkHttp and Retrofit.
/*
* Copyright (C) 2013 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.UUID;
package com.android.dex;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicInteger;
public class Summary {
public static void main(String[] args) throws IOException {
@swankjesse
swankjesse / PersonProtos.java
Created August 23, 2013 20:43
Protocol Buffers from protoc 2.5.0.
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: person.proto
package com.squareup.wire.protos.person;
public final class PersonProtos {
private PersonProtos() {}
public static void registerAllExtensions(
com.google.protobuf.ExtensionRegistry registry) {
}
@swankjesse
swankjesse / Person.java
Created August 23, 2013 20:45
Protocol Buffers from Wire 1.0.0.
// Code generated by Wire protocol buffer compiler, do not edit.
// Source file: /Users/jwilson/Square/wire/wire-runtime/src/test/proto/person.proto
package com.squareup.wire.protos.person;
import com.squareup.wire.Message;
import com.squareup.wire.ProtoEnum;
import com.squareup.wire.ProtoField;
import java.util.Collections;
import java.util.List;