Skip to content

Instantly share code, notes, and snippets.

View dsmf's full-sized avatar

Matthias Fischer dsmf

  • doubleSlash Net-Business GmbH
View GitHub Profile
@dsmf
dsmf / PojoTest.java
Last active January 30, 2025 14:24
POJO Test Example (OpenPOJO)
package com.example.openpojo;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.params.ParameterizedTest;
@dsmf
dsmf / FP.groovy
Created January 22, 2025 17:30
Freeplane: MindMap for Estimation with Automatic Sum
def static childAttribSum(parentNode, attributeName) {
parentNode.children.sum(0){ it[attributeName].num0 }
}
@dsmf
dsmf / RemoveTestPrefixAnReplaceUnderscores.java
Last active January 22, 2025 17:02
JUnit display name generator that removes "test" prefix and replaces underscores with space
import java.lang.reflect.Method;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.DisplayNameGenerator;
/**
* Display name generator that removes the "test" prefix from test names and replaces underscores with spaces.<br><br>
*
* Example:
@dsmf
dsmf / CsvReadCreateTableFromFile.java
Created December 6, 2024 22:48
Query CSV file using Java and H2
try (final Statement stmt = conn.createStatement()) {
stmt.execute(
"CREATE TABLE my_tablename AS " +
"SELECT * FROM " +
"CSVREAD('%s')".formatted(csvFilePath)
);
}
@dsmf
dsmf / java exception handling
Last active October 10, 2024 22:43
Error Handling - Traditional vs Java Exception Handling
readFile {
try {
open the file;
determine its size;
allocate that much memory;
read the file into memory;
close the file;
} catch (fileOpenFailed) {
doSomething;
} catch (sizeDeterminationFailed) {
@dsmf
dsmf / JCamelCaseToSpacesDisplayNameGenerator
Last active July 12, 2024 08:29
JUnit Camel Case to Space DisplayNameGenerator
import java.lang.reflect.Method;
import org.junit.jupiter.api.DisplayNameGenerator;
/**
* example: "whenNotAdminRoleThenForbidden" -> "when Not Admin Role Then Forbidden"
*/
public class CamelCaseToSpacesDisplayNameGenerator implements DisplayNameGenerator {
@dsmf
dsmf / StringUtil.java
Last active February 26, 2024 13:14
JUnit: MethodSource und Nested
public class StringUtil {
/**
* Extracts the last part of a comma-separated String and trims off leading and trailing whitespace.
*/
public static String extractLastTrimmed(String str) {
// implementation omitted
}
// more String helper methods
@dsmf
dsmf / push-to-all-remotes.sh
Created November 22, 2023 18:30
git helper script: push to all remotes
#!/bin/bash
# source: generated via ChatGPT and edited
commitMsgHookTempl=./git-commit-hooks/commit-msg
commitMsgHook=.git/hooks/commit-msg
if [ -f "$commitMsgHook" ]; then
read -p "commit-msg file already exists. Do you want to update it? (y/n): " updateChoice
if [ "$updateChoice" == "y" ]; then
@dsmf
dsmf / MyIntegrationTest.java
Created October 20, 2023 18:10
Blog - JUnit TestWatcher
@ExtendWith(StopProcessingIfAnyTestFailedExtension.class)
public class MyIntegrationTest {
@Test
@Order(1)
void integration_test_step_01() throws Exception {
...
}
@Test