Skip to content

Commit

Permalink
Fix Eclipse null warnings in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
agentgt committed Dec 11, 2024
1 parent 92e7fbd commit 9ab3b94
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 16 deletions.
4 changes: 4 additions & 0 deletions etc/eea/org/junit/jupiter/api/Assertions.eea
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class org/junit/jupiter/api/Assertions
assertThrows
<T:Ljava/lang/Throwable;>(Ljava/lang/Class<TT;>;Lorg/junit/jupiter/api/function/Executable;)TT;
<T:Ljava/lang/Throwable;>(Ljava/lang/Class<TT;>;Lorg/junit/jupiter/api/function/Executable;)T1T;
19 changes: 11 additions & 8 deletions etc/eea/prefs/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.annotationPath.allLocations=enabled
org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=javax.annotation.Nonnull,org.jetbrains.annotations.NotNull,org.checkerframework.checker.nullness.qual.NonNull,org.springframework.lang.NonNull,edu.umd.cs.findbugs.annotations.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=javax.annotation.Nullable,com.snaphop.annotation.TypeNullable,org.jetbrains.annotations.Nullable,org.checkerframework.checker.nullness.qual.Nullable,org.springframework.lang.Nullable,org.jspecify.nullness.Nullable,edu.umd.cs.findbugs.annotations.Nullable
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=warning
org.eclipse.jdt.core.compiler.annotation.nonnull=org.jspecify.annotations.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=org.eclipse.jdt.annotation.NonNull,org.jetbrains.annotations.NotNull,org.checkerframework.checker.nullness.qual.NonNull,org.springframework.lang.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.jspecify.annotations.NullMarked
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=io.jstach.ezkv.kvs.FakeNonNullByDefault,org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.notowning=org.eclipse.jdt.annotation.NotOwning
org.eclipse.jdt.core.compiler.annotation.nullable=org.jspecify.annotations.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=org.eclipse.jdt.annotation.Nullable,org.jetbrains.annotations.Nullable,org.checkerframework.checker.nullness.qual.Nullable,org.springframework.lang.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.annotation.owning=org.eclipse.jdt.annotation.Owning

org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* This annotation is a hack provided for Eclipse Null analysis support. See
* https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3434
*
* It is not public API and will be removed in the future once Eclipse supports JSpecify.
*
* The Eclipse EEA are stored in etc/eea and the Eclipse preferences needed are in
* etc/eea/prefs.
*/
@Documented
@Retention(RetentionPolicy.CLASS)
@interface FakeNonNullByDefault {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.PrintStream;
import java.util.Objects;
import java.util.stream.Stream;

Expand All @@ -14,6 +15,8 @@

class DefaultSedParserPropertiesTest {

static PrintStream out = Objects.requireNonNull(System.out);

@ParameterizedTest(name = "{0}")
@MethodSource("provideTestCases")
void testSedParser(String testName, String sedPattern, String input, @Nullable String expectedOutput) {
Expand All @@ -22,17 +25,17 @@ void testSedParser(String testName, String sedPattern, String input, @Nullable S
// Execute the command and verify the output
String result = command.execute(input);
if (!Objects.equals(result, expectedOutput)) {
System.out.format("test: %s, pattern: %s, input: %s, expected: %s\n", testName, sedPattern, input,
out.format("test: %s, pattern: %s, input: %s, expected: %s\n", testName, sedPattern, input,
expectedOutput);
System.out.println(command);
System.out.println(new Tokenizer(sedPattern).tokenize());
out.println(command);
out.println(new Tokenizer(sedPattern).tokenize());
}
assertEquals(expectedOutput, result);
}
catch (SedParserException e) {
String result = e.error.toString();
if (!Objects.equals(result, expectedOutput)) {
System.out.format("test: %s, pattern: %s, input: %s, expected: %s\n", testName, sedPattern, input,
out.format("test: %s, pattern: %s, input: %s, expected: %s\n", testName, sedPattern, input,
expectedOutput);
}
assertEquals(expectedOutput, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.PrintStream;
import java.util.Objects;

import org.junit.jupiter.api.Test;

import io.jstach.ezkv.kvs.DefaultSedParser.Command;
import io.jstach.ezkv.kvs.DefaultSedParser.Tokenizer;

class DefaultSedParserTest {

static PrintStream out = Objects.requireNonNull(System.out);

@Test
void testSubstitutionCommandWithoutAddress() {
{
Expand Down Expand Up @@ -99,7 +104,7 @@ void testInvalidDeleteCommandSyntax() {
void testInvalidCommand() {
String input = "/match/ x/foo/bar/";
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
System.out.println(new Tokenizer(input).tokenize());
out.println(new Tokenizer(input).tokenize());
DefaultSedParser.parseCommand(input);
});

Expand All @@ -110,7 +115,7 @@ void testInvalidCommand() {
void testSubstitutionCommandInvalidSyntax() {
String input = "s/foo/bar";
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
System.out.println(new Tokenizer(input).tokenize());
out.println(new Tokenizer(input).tokenize());
DefaultSedParser.parseCommand(input);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Collectors;

Expand All @@ -18,6 +20,8 @@

class KeyValuesSystemTest {

static PrintStream out = Objects.requireNonNull(System.out);

/*
* Yes it is ridiculous how this is all one test at the moment. It is essentially a
* smoke test and not a unit test.
Expand Down Expand Up @@ -60,8 +64,14 @@ public Logger getLogger() {
assertEquals(expected, actual);
}

// TODO Checker and Eclipse conflict here and both have bugs
// Eclipse needs the witness to infer nonnull
// Checker doesn't like the witness not having KeyFor which this library
// does not care bout and to be honest is a bug with checker
// more so than eclipse.
var map = Map.of("fromMap2", "2", "fromMap1", "1");

@SuppressWarnings("null")
var kvs = KeyValuesSystem.builder()
.environment(environment)
.build() //
Expand All @@ -71,7 +81,7 @@ public Logger getLogger() {
.add("extra", KeyValues.builder().add(map.entrySet()).build())
.load();

System.out.println(kvs);
out.println(kvs);
{
String actual = kvs.toString();
String expected = """
Expand Down
6 changes: 5 additions & 1 deletion ezkv-kvs/src/test/java/io/jstach/ezkv/kvs/KeyValuesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.PrintStream;
import java.util.Map;
import java.util.Objects;

import org.junit.jupiter.api.Test;

class KeyValuesTest {

static PrintStream out = Objects.requireNonNull(System.out);

@Test
void testExpand() {

Expand Down Expand Up @@ -39,7 +43,7 @@ void testExpand() {
// Convert to a map
{
Map<String, String> actual = expanded.toMap();
System.out.println(actual); // {key1=value1, key2=value1-value3}
out.println(actual); // {key1=value1, key2=value1-value3}

Map<String, String> expected = Map.of("key1", "value1", "key2", "value1-value3");
assertEquals(expected, actual);
Expand Down

0 comments on commit 9ab3b94

Please sign in to comment.