Skip to content

Instantly share code, notes, and snippets.

View skuzzle's full-sized avatar

Simon Taddiken skuzzle

View GitHub Profile
@skuzzle
skuzzle / Test.java
Created March 31, 2022 15:27
Fun with raw types
package test;
import java.util.Optional;
public class Test {
interface GenericInterface<T> {
Optional<String> methodReturningOptionalOfString();
}
@skuzzle
skuzzle / App.java
Created May 4, 2021 06:37
Manually handling UTF-8 encoding failures
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.HttpStatus;
@skuzzle
skuzzle / ExampleTest.java
Last active May 3, 2021 11:27
Wiremock property injection for SpringBootTests
@SpringBootTest
@WithWiremock(injectHostInto = "your.application.property.serviceUrl")
public class ExampleTest {
@Autowired
private WiremockServcer wiremock;
@Value("${your.application.property.serviceUrl}")
private String serviceUrl;
@Test
void testWiremock() {
@skuzzle
skuzzle / friend-classes.md
Last active November 10, 2016 18:31
An approach to 'friend' classes in java

API designers might know the struggle: you have a package defining the public API as interfaces and then you have another package containing the implementation. How do you make the implementation accessible to the outside but also restrict unwanted instantiations?

Forbidding unwanted usage of your API actually makes it easier to use because it is harder to be used the wrong way.

Let's look at this simple example and start with a public service interface: