Skip to content

Commit

Permalink
Yet more junit4 removal
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 11, 2025
1 parent 62b75ab commit 060d129
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package tools.jackson.databind.ext.jdk8;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.*;
import java.util.stream.Stream;

Expand Down
69 changes: 0 additions & 69 deletions src/test/java/tools/jackson/databind/ext/jdk8/StreamTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,12 @@
import java.util.function.Consumer;
import java.util.stream.BaseStream;

import org.hamcrest.CustomMatcher;
import org.hamcrest.Description;
import org.hamcrest.core.AllOf;
import org.hamcrest.core.Is;
import org.junit.Rule;
import org.junit.rules.ExpectedException;

import tools.jackson.databind.DatabindException;
import tools.jackson.databind.ObjectMapper;

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

public abstract class StreamTestBase
// 19-Sep-2017, tatu: For some reason doing this will break `ExpectedException` rule.
// Typical auto-magic that I hate -- but this code came as contribution.
//extends tools.jackson.databind.DatabindTestUtil
{
@Rule
public final ExpectedException expectedException = ExpectedException.none();

protected final ObjectMapper objectMapper = new ObjectMapper();

/**
Expand All @@ -49,59 +35,4 @@ <T, S extends BaseStream<T, S>> void assertClosesOnSuccess(S baseStream, Consume
roundTrip.accept(baseStream.onClose(() -> closed.set(true)));
assertTrue(closed.get());
}

<T, S extends BaseStream<T, S>> void assertClosesOnRuntimeException(String exceptionMessage,
Consumer<S> roundTrip, S baseStream) {
AtomicBoolean closed = new AtomicBoolean();
initExpectedException(RuntimeException.class, exceptionMessage,closed);
roundTrip.accept(baseStream.onClose(() -> closed.set(true)));
}

<T, S extends BaseStream<T, S>> void assertClosesOnIoException(String exceptionMessage, Consumer<S> roundTrip,
S baseStream) {
AtomicBoolean closed = new AtomicBoolean();
this.expectedException.expect(new IsClosedMatcher(closed));
this.expectedException.expect(Is.isA(DatabindException.class));
this.expectedException.expectMessage(exceptionMessage);
roundTrip.accept(baseStream.onClose(() -> closed.set(true)));
}

<T, S extends BaseStream<T, S>> void assertClosesOnWrappedIoException(String exceptionMessage,
Consumer<S> roundTrip, S baseStream) {
AtomicBoolean closed = new AtomicBoolean();
final String actualMessage = exceptionMessage;
this.expectedException.expect(new IsClosedMatcher(closed));
this.expectedException.expect(Is.isA(DatabindException.class));
this.expectedException.expectMessage(actualMessage);
roundTrip.accept(baseStream.onClose(() -> closed.set(true)));
}

void initExpectedException(Class<? extends Throwable> cause, final String exceptionMessage, AtomicBoolean closed) {
this.expectedException.expect(AllOf.allOf(Is.isA(DatabindException.class), new IsClosedMatcher(closed)));
this.expectedException.expect(Is.isA(DatabindException.class));
this.expectedException.expectCause(Is.isA(cause));
this.expectedException.expectMessage(exceptionMessage);
}

/**
* Matcher that matches when the <code>StreamTestBase.closed()</code> value is set to true.
*/
static class IsClosedMatcher extends CustomMatcher<Object> {
final AtomicBoolean closed;

public IsClosedMatcher(AtomicBoolean closed) {
super("Check flag closed");
this.closed = closed;
}

@Override
public void describeMismatch(Object item, Description description) {
description.appendText("The onClose method was not called");
}

@Override
public boolean matches(Object item) {
return closed.get();
}
}
}

0 comments on commit 060d129

Please sign in to comment.