Skip to content

Commit

Permalink
Update junit 4 13 (elastic#16138)
Browse files Browse the repository at this point in the history
* test-deps: update junit to latest 4.13

* test-deps: address deprecation of ExpectedException

* test-deps: use org.junit.Assert.assertThrows
  • Loading branch information
yaauie authored May 3, 2024
1 parent 973c2ba commit 9e452d2
Show file tree
Hide file tree
Showing 33 changed files with 134 additions and 130 deletions.
2 changes: 1 addition & 1 deletion logstash-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ dependencies {
testImplementation "org.apache.logging.log4j:log4j-core:${log4jVersion}:tests"
testImplementation 'org.hamcrest:hamcrest:2.2'
testImplementation 'org.hamcrest:hamcrest-library:2.2'
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
testImplementation 'net.javacrumbs.json-unit:json-unit:2.3.0'
testImplementation 'org.elasticsearch:securemock:1.2'
testImplementation 'org.assertj:assertj-core:3.11.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import org.junit.runner.RunWith;
import org.junit.runners.Suite;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@RunWith(Suite.class)
Expand Down
14 changes: 6 additions & 8 deletions logstash-core/src/test/java/org/logstash/ValuefierTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@
import org.jruby.java.proxies.MapJavaProxy;
import org.jruby.javasupport.Java;
import org.jruby.runtime.builtin.IRubyObject;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.logstash.ext.JrubyTimestampExtLibrary;

import static junit.framework.TestCase.assertEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertThrows;

public class ValuefierTest extends RubyTestBase {

Expand Down Expand Up @@ -120,15 +121,12 @@ public void testZonedDateTime() {
assertEquals(zdt.toInstant().toEpochMilli(), result.getTimestamp().toEpochMilli());
}

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void testUnhandledObject() {
RubyMatchData md = new RubyMatchData(RubyUtil.RUBY);
exception.expect(MissingConverterException.class);
exception.expectMessage("Missing Converter handling for full class name=org.jruby.RubyMatchData, simple name=RubyMatchData");
Valuefier.convert(md);

MissingConverterException missingConverterException = assertThrows(MissingConverterException.class, () -> Valuefier.convert(md));
assertThat(missingConverterException.getMessage(), containsString("Missing Converter handling for full class name=org.jruby.RubyMatchData, simple name=RubyMatchData"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.logstash.ackedqueue.QueueTestHelpers.computeCapacityForMmapPageIO;
import static org.logstash.util.ExceptionMatcher.assertThrows;
import static org.junit.Assert.assertThrows;

public class QueueTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package org.logstash.common;

import org.hamcrest.MatcherAssert;
import org.junit.Assert;
import org.junit.Test;
import org.logstash.plugins.ConfigVariableExpander;
Expand Down Expand Up @@ -110,7 +111,7 @@ public void testPrecedenceOfSecretStoreValueKeepingSecrets() {
Collections.singletonMap(key, evVal));

Object expandedValue = cve.expand("${" + key + ":" + defaultValue + "}", true);
Assert.assertThat(expandedValue, instanceOf(SecretVariable.class));
MatcherAssert.assertThat(expandedValue, instanceOf(SecretVariable.class));
Assert.assertEquals(ssVal, ((SecretVariable) expandedValue).getSecretValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
import java.util.*;
import java.util.stream.Collectors;

import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class PipelineConfigTest extends RubyEnvTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import org.logstash.plugins.ConfigVariableExpander;
import org.logstash.config.ir.graph.QueueVertex;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.any;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.logstash.config.ir.DSL.*;
import static org.logstash.config.ir.PluginDefinition.Type.*;
import static org.logstash.config.ir.IRHelpers.randMeta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.logstash.config.ir.InvalidIRException;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.logstash.config.ir.IRHelpers.*;

@RunWith(Theories.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.logstash.config.ir.IRHelpers;
import org.logstash.config.ir.InvalidIRException;

import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.*;

public class EdgeTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.logstash.config.ir.IRHelpers.createTestExpression;
import static org.logstash.config.ir.IRHelpers.createTestVertex;
import static org.logstash.config.ir.IRHelpers.randMeta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import java.util.Collections;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.logstash.config.ir.IRHelpers.*;

public class IfVertexTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import java.util.Map;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.logstash.config.ir.IRHelpers.*;

public class PluginVertexTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.Collection;
import java.util.stream.Collectors;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

public class ObservedExecutionTest extends RubyEnvTestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import org.assertj.core.api.Assertions;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.jruby.RubyBoolean;
import org.jruby.RubyHash;
import org.jruby.RubyString;
Expand Down Expand Up @@ -93,7 +94,7 @@ public void correctlyRaiseRubyRuntimeErrorWhenGivenInvalidFieldReferences() {
try {
event.ruby_set_field(context, key, value);
} catch (RuntimeError rubyRuntimeError) {
Assert.assertThat(rubyRuntimeError.getLocalizedMessage(), CoreMatchers.containsString("Invalid FieldReference"));
MatcherAssert.assertThat(rubyRuntimeError.getLocalizedMessage(), CoreMatchers.containsString("Invalid FieldReference"));
return;
}
Assert.fail("expected ruby RuntimeError was not thrown.");
Expand All @@ -109,7 +110,7 @@ public void correctlySetsValueWhenGivenMapWithKeysThatHaveFieldReferenceSpecialC

event.ruby_set_field(context, key, value);
IRubyObject retrievedValue = event.ruby_get_field(context, key);
Assert.assertThat(retrievedValue, CoreMatchers.equalTo(value));
MatcherAssert.assertThat(retrievedValue, CoreMatchers.equalTo(value));

RubyHash eventHash = (RubyHash) event.ruby_to_hash_with_metadata(context);
IRubyObject nestedValue = eventHash.dig(context, rubyString("foo"), rubyString("il[[]]]legal"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
import java.util.Map;
import java.util.function.Consumer;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;

public class ExtendedFlowMetricTest {
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import java.util.List;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.logstash.instrument.metrics.SimpleFlowMetric.LIFETIME_KEY;
import static org.logstash.instrument.metrics.SimpleFlowMetric.CURRENT_KEY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.logstash.secret.SecretIdentifier;
import org.logstash.secret.store.backend.JavaKeyStore;
Expand All @@ -36,6 +35,7 @@
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThrows;
import static org.logstash.secret.store.SecretStoreFactory.ENVIRONMENT_PASS_KEY;
import static org.logstash.secret.store.SecretStoreFactory.KEYSTORE_ACCESS_KEY;
import static org.logstash.secret.store.SecretStoreFactory.LOGSTASH_MARKER;
Expand All @@ -49,9 +49,6 @@ public class SecretStoreFactoryTest {
@Rule
public TemporaryFolder folder = new TemporaryFolder();

@Rule
public ExpectedException thrown = ExpectedException.none();

private static final SecretStoreFactory secretStoreFactory = SecretStoreFactory.fromEnvironment();

@Test
Expand All @@ -65,12 +62,12 @@ public void testAlternativeImplementation() {

@Test
public void testAlternativeImplementationInvalid() {
thrown.expect(SecretStoreException.ImplementationNotFoundException.class);
SecureConfig secureConfig = new SecureConfig();
secureConfig.add("keystore.classname", "junk".toCharArray());
SecretStore secretStore = secretStoreFactory.load(secureConfig);
assertThat(secretStore).isInstanceOf(MemoryStore.class);
validateMarker(secretStore);

assertThrows(SecretStoreException.ImplementationNotFoundException.class, () -> {
secretStoreFactory.load(secureConfig);
});
}

@Test
Expand Down Expand Up @@ -140,9 +137,10 @@ public void testDefaultLoadWithEnvPass() throws Exception {
*/
@Test
public void testErrorLoading() {
thrown.expect(SecretStoreException.LoadException.class);
//default implementation requires a path
secretStoreFactory.load(new SecureConfig());
assertThrows(SecretStoreException.LoadException.class, () -> {
//default implementation requires a path
secretStoreFactory.load(new SecureConfig());
});
}

private void validateMarker(SecretStore secretStore) {
Expand Down
Loading

0 comments on commit 9e452d2

Please sign in to comment.