Skip to content
Permalink
Browse files

refinements and fixes

  • Loading branch information...
elucash committed May 16, 2019
1 parent 7948cd2 commit 97344782555e43f0c55f14ad45f03213dc1b1e3b
@@ -1,9 +1,11 @@
package io.immutables.that;

import java.util.Arrays;
import java.util.stream.Collectors;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* {@code Assert.that}: Minimalistic, extensible and attentive to details assertions.
@@ -47,8 +49,8 @@ private Assert() {}
* @return that optional
*/
@CheckReturnValue
public static <T> That.Optional<T> that(java.util.Optional<T> actual) {
class Tested extends That.What<java.util.Optional<T>, That.Optional<T>> implements That.Optional<T> {}
public static <T> That.Optional<T> that(Optional<T> actual) {
class Tested extends That.What<Optional<T>, That.Optional<T>> implements That.Optional<T> {}
return new Tested().set(actual);
}

@@ -58,8 +60,8 @@ private Assert() {}
* @return that iterable
*/
@CheckReturnValue
public static <T> That.Iterable<T> that(java.lang.Iterable<T> actual) {
class Tested extends That.What<java.lang.Iterable<T>, That.Iterable<T>> implements That.Iterable<T> {}
public static <T> That.Iterable<T> that(Iterable<T> actual) {
class Tested extends That.What<Iterable<T>, That.Iterable<T>> implements That.Iterable<T> {}
return new Tested().set(actual);
}

@@ -69,8 +71,8 @@ private Assert() {}
* @return that iterable
*/
@CheckReturnValue
public static <T> That.Iterable<T> that(java.util.stream.Stream<T> actual) {
class Tested extends That.What<java.lang.Iterable<T>, That.Iterable<T>> implements That.Iterable<T> {}
public static <T> That.Iterable<T> that(Stream<T> actual) {
class Tested extends That.What<Iterable<T>, That.Iterable<T>> implements That.Iterable<T> {}
return new Tested().set(actual.collect(Collectors.toList()));
}

@@ -82,7 +84,7 @@ private Assert() {}
@CheckReturnValue
@SafeVarargs
public static <T> That.Iterable<T> that(T... actual) {
class Tested extends That.What<java.lang.Iterable<T>, That.Iterable<T>> implements That.Iterable<T> {}
class Tested extends That.What<Iterable<T>, That.Iterable<T>> implements That.Iterable<T> {}
return new Tested().set(Arrays.asList(actual));
}

@@ -151,7 +153,7 @@ private Assert() {}
*/
@CheckReturnValue
public static That.Int that(@Nullable Character actual) {
return that(actual == null ? null : (int) actual.charValue());
return that(actual == null ? null : (int) actual.charValue());
}

/**
@@ -68,16 +68,18 @@ private String showSourceHint() {

return Arrays.asList(stack)
.subList(start, end)
.toArray(new StackTraceElement[] {});
.toArray(new StackTraceElement[]{});
}

private static boolean isThatPackageFrame(StackTraceElement s) {
return s.getClassName().startsWith(AssertionError.class.getPackage().getName());
}

private static boolean isTestClassFrame(StackTraceElement e) {
return e.getFileName().startsWith(TEST_SUFFIX_OR_PREFIX)
|| e.getFileName().endsWith(TEST_SUFFIX_OR_PREFIX);
String fileName = e.getFileName();
if (fileName == null) return false;
return fileName.startsWith(TEST_SUFFIX_OR_PREFIX)
|| fileName.endsWith(TEST_SUFFIX_OR_PREFIX);
}

private static String findSourceLine(StackTraceElement[] stack) {
@@ -113,10 +115,9 @@ private static String getPackagePath(String qualifiedName) {
private static String readLine(String resourceName, int lineNumber) {
assert lineNumber > 0;

@Nullable InputStream stream = AssertionError.class.getResourceAsStream(resourceName);
if (stream == null)
return "";

@Nullable
InputStream stream = AssertionError.class.getResourceAsStream(resourceName);
if (stream == null) return "";
try (
Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8);
BufferedReader r = new BufferedReader(in)) {
@@ -20,7 +20,7 @@

/**
* The maximum length for {@link #expected} and {@link #actual} strings to show. When
* {@link #compactionLength} is exceeded, the Strings are shortened.
* {@code compactionLength} is exceeded, the Strings are shortened.
*/
private final int compactionLength;
private final String expected;
@@ -51,7 +51,7 @@ static String trim(@Nullable Object actual) {
return diff(actual, actual).get(0);
}

List<String> asList() {
private List<String> asList() {
String prefix = prefix();
String suffix = suffix(prefix);

0 comments on commit 9734478

Please sign in to comment.
You can’t perform that action at this time.