Skip to content

Commit

Permalink
#980 - Migrate to JUnit 5.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregturn committed Apr 8, 2019
1 parent a0937f7 commit 3a8b37b
Show file tree
Hide file tree
Showing 94 changed files with 544 additions and 467 deletions.
27 changes: 23 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<java-module-name>spring.hateoas</java-module-name>
<jsonpath.version>2.2.0</jsonpath.version>
<jsr305.version>3.0.2</jsr305.version>
<junit.version>5.3.2</junit.version>
<minidevjson.version>2.2.1</minidevjson.version>
<reactor-bom.version>Californium-SR4</reactor-bom.version>
<slf4j.version>1.7.25</slf4j.version>
Expand Down Expand Up @@ -418,6 +419,13 @@
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>${junit.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -548,9 +556,14 @@
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

Expand All @@ -563,7 +576,7 @@

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
Expand All @@ -587,6 +600,12 @@
<artifactId>jadler-all</artifactId>
<version>1.3.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.HashMap;
import java.util.Map;

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

/**
* @author Oliver Drotbohm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.io.StringWriter;
import java.io.Writer;

import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;

import com.fasterxml.jackson.databind.ObjectMapper;

Expand All @@ -33,7 +33,7 @@ public abstract class AbstractJackson2MarshallingIntegrationTest {

protected ObjectMapper mapper;

@Before
@BeforeEach
public void setUp() {
mapper = new ObjectMapper();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.hateoas;

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

import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Collections;
import java.util.Set;

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

/**
* Unit tests for {@link CollectionModel}.
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.*;

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

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.Collections;

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

/**
* Unit tests for {@link EntityModel}.
Expand Down Expand Up @@ -66,8 +66,11 @@ public void notEqualForDifferentLinks() {
assertThat(right).isNotEqualTo(left);
}

@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsCollectionContent() {
new EntityModel<Object>(Collections.emptyList());

assertThatIllegalArgumentException().isThrownBy(() -> {
new EntityModel<Object>(Collections.emptyList());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import lombok.Value;

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

/**
* @author Greg Turnquist
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.*;

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

/**
* Integration tests for {@link org.springframework.hateoas.Link} marshaling.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package org.springframework.hateoas;

import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.CoreMatchers.*;
import static org.assertj.core.api.Assumptions.*;
import static org.mockito.Mockito.*;

import java.io.StringWriter;
Expand All @@ -25,8 +25,7 @@
import java.util.Collections;

import org.apache.commons.io.output.WriterOutputStream;
import org.junit.Assume;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.hateoas.PagedModel.PageMetadata;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpOutputMessage;
Expand Down Expand Up @@ -59,7 +58,7 @@ public class Jackson2PagedResourcesIntegrationTest {
@Test
public void serializesPagedResourcesCorrectly() throws Exception {

Assume.assumeThat(SPRING_4_2_WRITE_METHOD, is(notNullValue()));
assumeThat(SPRING_4_2_WRITE_METHOD).isNotNull();

User user = new User();
user.firstname = "Dave";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

import com.fasterxml.jackson.annotation.JsonAutoDetect;

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.*;

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

/**
* Integration tests for {@link org.springframework.hateoas.RepresentationModel}.
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.*;

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

/**
* Integration tests for {@link Link} marshaling.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.Set;
import java.util.stream.Collectors;

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

/**
* @author Greg Turnquist
Expand Down
51 changes: 36 additions & 15 deletions src/test/java/org/springframework/hateoas/LinkUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.Collections;

import org.apache.commons.io.output.ByteArrayOutputStream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.ResolvableType;
import org.springframework.hateoas.support.Employee;
import org.springframework.http.HttpMethod;
Expand Down Expand Up @@ -59,25 +59,37 @@ public void createsLinkFromRelAndHref() {
}

@SuppressWarnings("null")
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullHref() {
new Link(null);

assertThatIllegalArgumentException().isThrownBy(() -> {
new Link(null);
});
}

@SuppressWarnings("null")
@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNullRel() {
new Link("foo", (String) null);

assertThatIllegalArgumentException().isThrownBy(() -> {
new Link("foo", (String) null);
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsEmptyHref() {
new Link("");

assertThatIllegalArgumentException().isThrownBy(() -> {
new Link("");
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsEmptyRel() {
new Link("foo", "");

assertThatIllegalArgumentException().isThrownBy(() -> {
new Link("foo", "");
});
}

@Test
Expand Down Expand Up @@ -160,19 +172,28 @@ public void ignoresUnrecognizedAttributes() {
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsMissingRelAttribute() {
Link.valueOf("</something>;title=\"title\"");

assertThatIllegalArgumentException().isThrownBy(() -> {
Link.valueOf("</something>;title=\"title\"");
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsLinkWithoutAttributesAtAll() {
Link.valueOf("</something>");

assertThatIllegalArgumentException().isThrownBy(() -> {
Link.valueOf("</something>");
});
}

@Test(expected = IllegalArgumentException.class)
@Test
public void rejectsNonRFC5988String() {
Link.valueOf("foo");

assertThatIllegalArgumentException().isThrownBy(() -> {
Link.valueOf("foo");
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Arrays;
import java.util.Optional;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringUtils;

/**
Expand Down
34 changes: 23 additions & 11 deletions src/test/java/org/springframework/hateoas/PagedModelUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import java.util.Collections;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.hateoas.PagedModel.PageMetadata;

/**
Expand All @@ -34,7 +34,7 @@ public class PagedModelUnitTest {

PagedModel<Object> resources;

@Before
@BeforeEach
public void setUp() {
resources = new PagedModel<>(Collections.emptyList(), metadata);
}
Expand All @@ -58,33 +58,45 @@ public void discoversPreviousLink() {
/**
* @see #89
*/
@Test(expected = IllegalArgumentException.class)
@Test
public void preventsNegativePageSize() {
new PageMetadata(-1, 0, 0);

assertThatIllegalArgumentException().isThrownBy(() -> {
new PageMetadata(-1, 0, 0);
});
}

/**
* @see #89
*/
@Test(expected = IllegalArgumentException.class)
@Test
public void preventsNegativePageNumber() {
new PageMetadata(0, -1, 0);

assertThatIllegalArgumentException().isThrownBy(() -> {
new PageMetadata(0, -1, 0);
});
}

/**
* @see #89
*/
@Test(expected = IllegalArgumentException.class)
@Test
public void preventsNegativeTotalElements() {
new PageMetadata(0, 0, -1);

assertThatIllegalArgumentException().isThrownBy(() -> {
new PageMetadata(0, 0, -1);
});
}

/**
* @see #89
*/
@Test(expected = IllegalArgumentException.class)
@Test
public void preventsNegativeTotalPages() {
new PageMetadata(0, 0, 0, -1);

assertThatIllegalArgumentException().isThrownBy(() -> {
new PageMetadata(0, 0, 0, -1);
});
}

/**
Expand Down
Loading

0 comments on commit 3a8b37b

Please sign in to comment.