Migrate MongoDB to JUnit 5 (except for ClassRule).

See #583.
This commit is contained in:
Mark Paluch
2021-04-28 15:37:28 +02:00
parent e565f33872
commit ead318ce8d
29 changed files with 366 additions and 455 deletions

View File

@@ -24,39 +24,34 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.gridfs.GridFsOperations;
import org.springframework.data.mongodb.gridfs.GridFsResource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.util.StreamUtils;
import com.mongodb.client.gridfs.model.GridFSFile;
/**
* Tests to show the usage of {@link GridFsOperations} with Spring Data MongoDB.
*
* @author Hartmut Lang
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class GridFsTests {
@DataMongoTest
class GridFsTests {
@Autowired GridFsOperations gridFsOperations;
@Before
public void before() {
@BeforeEach
void before() {
gridFsOperations.delete(new Query());
}
@Test
public void shouldStoreSimpleFile() throws IOException {
void shouldStoreSimpleFile() throws IOException {
try (InputStream is = new BufferedInputStream(new ClassPathResource("./example-file.txt").getInputStream())) {
// store file
@@ -71,7 +66,7 @@ public class GridFsTests {
}
@Test
public void shouldStoreFileWithMetadata() throws IOException {
void shouldStoreFileWithMetadata() throws IOException {
try (InputStream is = new BufferedInputStream(new ClassPathResource("./example-file.txt").getInputStream())) {
@@ -86,7 +81,7 @@ public class GridFsTests {
}
@Test
public void shouldStoreAndReadFile() throws IOException {
void shouldStoreAndReadFile() throws IOException {
byte[] bytes;
try (InputStream is = new BufferedInputStream(new ClassPathResource("./example-file.txt").getInputStream())) {