Skip to content

Commit

Permalink
[JUnit 5] Migrate tests which can be easily converted (#2878)
Browse files Browse the repository at this point in the history
JUnit 4 -> 5 migrations are often done in a 3-step process:

1. Update dependencies to JUnit 5, including the vintage module, causing all tests to leverage the new JUnit 5 Platform (completed in #2850)
2. Incrementally migrate JUnit 4 tests to JUnit 5 tests
3. Once no JUnit 4 usage remains, remove the dependency on the vintage module

This PR begins step 2 by migrating tests which can be easily converted.

IntelliJ provides a convenient way to migrate tests but unfortunately there is no support for automatically migrating JUnit 4 tests which leverage any of the following:

1. The `expected` parameter in test annotations
2. The `timeout` parameter in test annotations
3. The class-level `@RunWith` annotation (e.g., `@RunWith(Parameterized.class)` and `@RunWith(MockitoJUnitRunner.class)`)

Therefore, this PR leverages the migrate functionality but defers the above scenarios as follows:

```
grep -r -e "@test(" -e "@RunWith(" . | cut -d ':' -f1 | xargs -I {} git restore {}
```

All changes in this PR are fully automated with the migrate functionality, except for the changes to the top-level pom.xml to add `org.junit.*` to both `ignoredUsedUndeclaredDependency` and `ignoredUnusedDeclaredDependency`.

Additionally, there were a few cases of the migrate functionality migrating a superclass but not being able to migrate a subclass (due to the above limitations). The superclass was restored in this case.
  • Loading branch information
Bennett-Lynch authored Dec 2, 2021
1 parent 759e2ac commit 4289e9a
Show file tree
Hide file tree
Showing 613 changed files with 1,582 additions and 1,685 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import java.io.File;
import java.nio.file.Paths;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.lite.regions.model.Partition;
import software.amazon.awssdk.codegen.lite.regions.model.Partitions;

Expand All @@ -35,7 +35,7 @@ public class RegionGenerationTest {
private File endpoints;
private Partitions partitions;

@Before
@BeforeEach
public void before() throws Exception {
this.endpoints = Paths.get(getClass().getResource(ENDPOINTS).toURI()).toFile();
this.partitions = RegionMetadataLoader.build(endpoints);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class RegionValidationUtilTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static org.junit.Assert.assertTrue;

import java.io.File;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.intermediate.ShapeModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@


import java.io.File;
import org.junit.BeforeClass;
import org.junit.jupiter.api.BeforeAll;
import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.rules.ExpectedException;
import software.amazon.awssdk.codegen.C2jModels;
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
Expand All @@ -42,7 +42,7 @@ public class UseLegacyEventGenerationSchemeProcessorTest {
private static ServiceModel serviceModel;


@BeforeClass
@BeforeAll
public static void setup() {
String c2jFilePath = UseLegacyEventGenerationSchemeProcessorTest.class.getResource(RESOURCE_ROOT + "/service-2.json").getFile();
File c2jFile = new File(c2jFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.Test;
import org.junit.jupiter.api.Test;

public class CodeTransformerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.poet.ClassSpec;

public final class PoetGeneratorTaskIntegrationTest {
Expand All @@ -54,7 +54,7 @@ public void canGenerateJavaClass() throws Exception {
assertThat(contents, both(containsString(PACKAGE)).and(startsWith(fileHeader)));
}

@After
@AfterEach
public void cleanUp() {
tempDirectories.forEach(safeConsumer(tempDir -> {
List<Path> files = Files.walk(Paths.get(tempDir)).collect(toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class UnusedImportRemoverTest {

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

import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;


public class DocumentationUtilsTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class UtilsTest {
final Map<String,String> capitalizedToUncapitalized = new HashMap<String,String>() {{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.jmespath.component.Comparator;
import software.amazon.awssdk.codegen.jmespath.component.Expression;
import software.amazon.awssdk.codegen.jmespath.parser.JmesPathParser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static software.amazon.awssdk.codegen.TestStringUtils.toPlatformLfs;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.docs.DocumentationBuilder;

public class DocumentationBuilderTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.io.File;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.C2jModels;
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class PaginatorDefinitionTest {

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

import com.squareup.javapoet.CodeBlock;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.jupiter.api.Test;

/**
* Validate functionality of the {@link PoetCollectors}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static software.amazon.awssdk.codegen.poet.PoetMatchers.generatesTo;

import java.util.function.Function;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.poet.ClassSpec;
import software.amazon.awssdk.codegen.poet.ClientTestModels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static software.amazon.awssdk.codegen.poet.PoetMatchers.generatesTo;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.poet.ClassSpec;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static software.amazon.awssdk.codegen.poet.PoetMatchers.generatesTo;

import java.io.IOException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.model.intermediate.EnumModel;
import software.amazon.awssdk.codegen.model.intermediate.ShapeModel;
import software.amazon.awssdk.codegen.model.intermediate.ShapeType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static software.amazon.awssdk.codegen.poet.PoetMatchers.generatesTo;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.poet.ClientTestModels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static software.amazon.awssdk.codegen.poet.PoetMatchers.generatesTo;

import java.util.function.BiFunction;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import java.io.File;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.C2jModels;
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
Expand All @@ -32,7 +32,7 @@
public class AwsServiceBaseRequestSpecTest {
private static IntermediateModel intermediateModel;

@BeforeClass
@BeforeAll
public static void setUp() throws IOException {
File serviceModelFile = new File(AwsModelSpecTest.class.getResource("service-2.json").getFile());
File customizationConfigFile = new File(AwsModelSpecTest.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import java.io.File;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.C2jModels;
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
Expand All @@ -32,7 +32,7 @@
public class AwsServiceBaseResponseSpecTest {
private static IntermediateModel intermediateModel;

@BeforeClass
@BeforeAll
public static void setUp() throws IOException {
File serviceModelFile = new File(AwsModelSpecTest.class.getResource("service-2.json").getFile());
File customizationConfigFile = new File(AwsModelSpecTest.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import java.io.File;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.C2jModels;
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
Expand All @@ -31,7 +31,7 @@
public class BaseExceptionClassSpecTest {
private static IntermediateModel intermediateModel;

@BeforeClass
@BeforeAll
public static void setUp() throws IOException {
File serviceModelFile = new File(AwsModelSpecTest.class.getResource("service-2.json").getFile());
File customizationConfigFile = new File(AwsModelSpecTest.class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import java.io.File;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.C2jModels;
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
Expand All @@ -33,7 +33,7 @@ public class ResponseMetadataSpecTest {
private static IntermediateModel model;
private static IntermediateModel modelWithCustomizedResponseMetadata;

@BeforeClass
@BeforeAll
public static void setUp() throws IOException {
File serviceModelFile = new File(AwsModelSpecTest.class.getResource("service-2.json")
.getFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import java.io.File;
import java.io.IOException;
import java.util.Map;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.C2jModels;
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
Expand All @@ -42,7 +42,7 @@ public class PaginatedResponseClassSpecTest {
private static Paginators paginators;
private static Map<String, String> paginationCustomization;

@BeforeClass
@BeforeAll
public static void setUp() throws IOException {
File serviceModelFile = new File(PaginatedResponseClassSpecTest.class.getResource("service-2.json").getFile());
File customizationConfigFile = new File(PaginatedResponseClassSpecTest.class.getResource("customization.config")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,9 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static software.amazon.awssdk.codegen.poet.PoetMatchers.generatesTo;

import java.io.File;
import java.io.IOException;
import org.junit.BeforeClass;
import org.junit.Test;
import software.amazon.awssdk.codegen.C2jModels;
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
import software.amazon.awssdk.codegen.model.service.ServiceModel;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.codegen.poet.ClassSpec;
import software.amazon.awssdk.codegen.poet.ClientTestModels;
import software.amazon.awssdk.codegen.poet.client.AsyncClientClass;
import software.amazon.awssdk.codegen.poet.client.AsyncClientInterface;
import software.amazon.awssdk.codegen.poet.client.ClientSimpleMethodsIntegrationTests;
import software.amazon.awssdk.codegen.poet.client.SyncClientClass;
import software.amazon.awssdk.codegen.poet.client.SyncClientInterface;
import software.amazon.awssdk.codegen.poet.paginators.PaginatedResponseClassSpecTest;
import software.amazon.awssdk.codegen.utils.ModelLoaderUtils;

public class WaitersClassSpecTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package software.amazon.awssdk.services.json;

import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.regions.Region;

@Generated("software.amazon.awssdk:codegen")
public class SimpleMethodsIntegrationTest {
private static JsonClient client;

@BeforeClass
@BeforeAll
public static void setup() {
if (JsonClient.serviceMetadata().regions().isEmpty()) {
client = JsonClient.builder().region(Region.US_EAST_1).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ArnResourceTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.util.Optional;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class ArnTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.core.internal.chunked.AwsChunkedEncodingConfig;
import software.amazon.awssdk.auth.signer.internal.chunkedencoding.AwsSignedChunkedEncodingInputStream;
import software.amazon.awssdk.authcrt.signer.SignerTestUtils;
Expand All @@ -25,7 +25,7 @@ public class AwsCrt4aSigningAdapterTest {
AwsCrt4aSigningAdapter crtSigningAdapter;
SigningConfigProvider configProvider;

@Before
@BeforeEach
public void setup() {
crtSigningAdapter = new AwsCrt4aSigningAdapter();
configProvider = new SigningConfigProvider();
Expand Down
Loading

0 comments on commit 4289e9a

Please sign in to comment.