dependency updates
This commit is contained in:
@ -24,29 +24,28 @@ import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class StreamUtils {
|
||||
public interface StreamUtils {
|
||||
|
||||
public static <T> Collector<T, ?, T> singletonCollector() {
|
||||
return getCollectorFunction(getListTSingleFunction());
|
||||
}
|
||||
default <T> Collector<T, ?, T> singletonCollector() {
|
||||
return getCollectorFunction(getListTSingleFunction());
|
||||
}
|
||||
|
||||
private static <T> Collector<T, ?, T> getCollectorFunction(Function<List<T>, T> listTFunction) {
|
||||
return Collectors.collectingAndThen(Collectors.toList(), listTFunction);
|
||||
}
|
||||
default <T> Collector<T, ?, T> getCollectorFunction(Function<List<T>, T> listTFunction) {
|
||||
return Collectors.collectingAndThen(Collectors.toList(), listTFunction);
|
||||
}
|
||||
|
||||
private static <T> Function<List<T>, T> getListTSingleFunction() {
|
||||
return list -> {
|
||||
if (list == null) {
|
||||
throw new IllegalStateException("List must not be null");
|
||||
}
|
||||
if (list.size() != 1) {
|
||||
throw new IllegalStateException("List contains not exactly one element (size=" + list.size() + ")");
|
||||
}
|
||||
return list.get(0);
|
||||
};
|
||||
}
|
||||
default <T> Function<List<T>, T> getListTSingleFunction() {
|
||||
return list -> {
|
||||
if (list == null) {
|
||||
throw new IllegalStateException("List must not be null");
|
||||
}
|
||||
if (list.size() != 1) {
|
||||
throw new IllegalStateException("List contains not exactly one element (size=" + list.size() + ")");
|
||||
}
|
||||
return list.get(0);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,7 +21,7 @@ package de.muehlencord.shared.util;
|
||||
*/
|
||||
public class StringEncodingException extends Exception {
|
||||
|
||||
protected final static String DEFAULT_MSG = "An encoding exception occurred";
|
||||
protected static final String DEFAULT_MSG = "An encoding exception occurred";
|
||||
|
||||
/**
|
||||
* Creates a new instance of
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright 2019 Joern Muehlencord (joern@muehlencord.de).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -15,38 +15,38 @@
|
||||
*/
|
||||
package de.muehlencord.shared.util;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Joern Muehlencord (joern@muehlencord.de)
|
||||
*/
|
||||
public class StringEncodingExceptionTest {
|
||||
|
||||
class StringEncodingExceptionTest {
|
||||
|
||||
|
||||
@Test
|
||||
void testDefaultConstructor() {
|
||||
StringEncodingException ex = new StringEncodingException();
|
||||
assertEquals(StringEncodingException.DEFAULT_MSG, ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMessageConstructor() {
|
||||
String msg = "Test message";
|
||||
StringEncodingException ex = new StringEncodingException(msg);
|
||||
assertEquals(ex.getMessage(), msg);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testRootcauseConstructor() {
|
||||
String msg = "Test message";
|
||||
StringEncodingException rootCause = new StringEncodingException();
|
||||
StringEncodingException ex = new StringEncodingException(msg, rootCause);
|
||||
assertEquals(ex.getMessage(), msg);
|
||||
assertEquals(ex.getCause(), rootCause);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefaultConstructor() {
|
||||
StringEncodingException ex = new StringEncodingException();
|
||||
assertTrue (ex.getMessage().equals (StringEncodingException.DEFAULT_MSG));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageConstructor() {
|
||||
String msg = "Test message";
|
||||
StringEncodingException ex = new StringEncodingException(msg);
|
||||
assertTrue (ex.getMessage().equals (msg));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRootcauseConstructor() {
|
||||
String msg = "Test message";
|
||||
StringEncodingException rootCause = new StringEncodingException();
|
||||
StringEncodingException ex = new StringEncodingException(msg, rootCause);
|
||||
assertTrue (ex.getMessage().equals (msg));
|
||||
assertTrue (ex.getCause().equals (rootCause));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user