Skip to content

Instantly share code, notes, and snippets.

View ledoyen's full-sized avatar
👶
mollycoddling

Loïc Ledoyen ledoyen

👶
mollycoddling
View GitHub Profile
@ledoyen
ledoyen / AllCombinations.java
Created May 13, 2022 14:26
Combinator Arguments provider for JUnit-Params
package com.github.ledoyen;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
git config --global --add remote.origin.fetch "+refs/pull/*/head:refs/remotes/origin/pr/*"
@ledoyen
ledoyen / gist:22fbe8a4a6e0e378935f84faae40f2e8
Created June 20, 2018 14:21
XML comparison with wildcards using XMLUnit
val diff = DiffBuilder.compare(expected).withTest(actual)
.withNodeMatcher(DefaultNodeMatcher(ElementSelectors.byNameAndAllAttributes, ElementSelectors.byName))
.ignoreWhitespace()
.ignoreComments()
.withDifferenceEvaluator(DifferenceEvaluators.chain(DifferenceEvaluators.Default, XmlWildcardDifferenceEvaluator()))
.checkForSimilar()
.build()
assertThat(diff.differences).isEmpty()
class XmlWildcardDifferenceEvaluator : DifferenceEvaluator {
@ledoyen
ledoyen / README.md
Last active April 5, 2018 18:49
Importer les données dans Alexandria Book Library

Importer les données dans Alexandria Book Library

1. (La première fois ou après un changement de schéma) Créer le schéma de la base locale

Installer une base MYSQL 4.1 Lancer le script create_schema.sql
C'est à dire, dans HeidiSQL :
Dans une onglet "requête":
Coller le contenu du fichier create_schema.sql
Cliquer sur la flèche bleu (executer ou F9)

@ledoyen
ledoyen / README.md
Last active September 6, 2017 23:11
Evaluate Javascript functions on JSON data in Java

Java8 is required.

With a method defined as:

private Object evaluate(String jsonDocument, String javascriptFunction) {
    ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
    try {
        String script = "var fun = function(document) {\n" +
                "    return JSON.parse(document)." + javascriptFunction + ";\n" +
                "};";
@ledoyen
ledoyen / main.rs
Created July 7, 2017 22:12
99 Bottles of Beer in Rust
fn main() {
bottlesong_rec(99);
bottlesong_loop(99);
}
fn bottlesong_rec(bottle_number: i32) {
if bottle_number > 0 {
println!("{0} bottle{1} of beer on the wall, {0} bottle{1} of beer.", bottle_number, compute_plural(bottle_number));
if bottle_number == 1 {
println!("Take one down and pass it around, no more bottles of beer on the wall.\n\n\
@ledoyen
ledoyen / README.md
Last active March 20, 2023 18:57
Binding HttpClient to MockMvc

Given two interfaces such as

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException;

public interface HttpClient<OUTPUT> {
@ledoyen
ledoyen / reactive-rabbit-java.md
Last active October 4, 2017 08:32
Reactive AMQP in Java

Reactive AMQP in Java

Using this Maven configuration

<dependencies>
	<dependency>
		<groupId>io.projectreactor</groupId>
		<artifactId>reactor-core</artifactId>
		<version>3.0.6.RELEASE</version>
	
@ledoyen
ledoyen / gist:069fa3ee759f6d600433
Last active August 29, 2015 14:19
[JAVA] Generate default values
package tools;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Optional;
import org.mockito.internal.util.Primitives;
import com.google.common.base.Preconditions;
@ledoyen
ledoyen / gist:42dd84bf3bba954cbaed
Last active August 29, 2015 14:16
[JAVA] Simulate class unloading

For testing purpose you may want to "unload" some classes.

Testing the new Spring Boot @ConditionalOnClass or @ConditionalOnMissingClass is a good example.

Once in your JUnit class, you usually don't get to modify the classpath to remove some jar and test that your application still works.

One way to do this test is to create a Maven project in a dedicated directory with a different pom.xml (and so a different classpath at runtime) and run tests in it from your main project with the invoker plugin. See how google does it in the auto-value project.

Another way to do it is to take advantage of the high mutability of Java and hack into the classloader to modify cached data :