Skip to content

Commit

Permalink
Junit4 assertion to Junit5 migration (#1166)
Browse files Browse the repository at this point in the history
Co-authored-by: Ernest Sadykov <xkr@fb.com>
  • Loading branch information
chaaransen and xokker committed Sep 26, 2022
1 parent 34a2280 commit 296076f
Show file tree
Hide file tree
Showing 37 changed files with 359 additions and 339 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.datatransferproject.cloud.google;

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

import com.google.cloud.datastore.Datastore;
import com.google.cloud.datastore.Transaction;
import com.google.cloud.datastore.testing.LocalDatastoreHelper;
Expand All @@ -12,7 +16,7 @@
import java.io.IOException;
import java.util.UUID;

import static org.junit.Assert.*;


public class GoogleCloudIdempotentImportExecutorTest {

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

package org.datatransferproject.cloud.google;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.cloud.datastore.Datastore;
Expand All @@ -31,7 +31,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.datatransferproject.cloud.local;

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

import com.google.common.collect.ImmutableMap;
import com.google.common.truth.Truth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.datatransferproject.datatransfer.backblaze.common;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

package org.datatransferproject.transfer.daybook.photos;

import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.datatransferproject.transfer.daybook.social;

import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import static com.google.common.truth.Truth.assertThat;
import static org.datatransferproject.transfer.facebook.photos.FacebookPhotosExporter.PHOTO_TOKEN_PREFIX;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.datatransferproject.transfer.facebook.videos;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import static com.google.common.truth.Truth.assertThat;
import static org.datatransferproject.datatransfer.google.photos.GooglePhotosExporter.ALBUM_TOKEN_PREFIX;
import static org.datatransferproject.datatransfer.google.photos.GooglePhotosExporter.PHOTO_TOKEN_PREFIX;
import static org.junit.Assert.assertNull;

import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package org.datatransferproject.datatransfer.google.photos;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.datatransferproject.datatransfer.google.photos;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static com.google.common.truth.Truth.assertThat;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -22,9 +20,9 @@ public void testSerialization() throws IOException, ClassNotFoundException {

ByteArrayInputStream bais = new ByteArrayInputStream(out.toByteArray());
Object readObject = new ObjectInputStream(bais).readObject();
assertThat(readObject, instanceOf(PhotoResult.class));
assertThat(readObject).isInstanceOf(PhotoResult.class);
PhotoResult deserialized = (PhotoResult) readObject;
assertThat(deserialized.getId(), equalTo(photoId));
assertThat(deserialized.getBytes(), equalTo(bytes));
assertThat(deserialized.getId()).isEqualTo(photoId);
assertThat(deserialized.getBytes()).isEqualTo(bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package org.datatransferproject.datatransfer.google.videos;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
Expand Down Expand Up @@ -175,8 +175,8 @@ public void importTwoVideosInDifferentAlbums() throws Exception {
null))))
.getBytes()
.get();
assertEquals("Expected the number of bytes to be the two files of 32L.", 64L, length);
assertEquals("Expected executor to have no errors.", 0, executor.getErrors().size());
assertEquals(64L, length,"Expected the number of bytes to be the two files of 32L.");
assertEquals(0, executor.getErrors().size(),"Expected executor to have no errors.");
}

@Test
Expand Down Expand Up @@ -236,8 +236,8 @@ public void failOneVideo() throws Exception {
photosLibraryClient,
executor);

assertEquals("Expected the number of bytes to be the one files of 32L.", 32L, length);
assertEquals("Expected executor to have one error.", 1, executor.getErrors().size());
assertEquals(32L, length,"Expected the number of bytes to be the one files of 32L.");
assertEquals(1, executor.getErrors().size(),"Expected executor to have one error.");
ErrorDetail errorDetail = executor.getErrors().iterator().next();
assertEquals("myId2", errorDetail.id());
assertThat(errorDetail.exception()).contains("Video item could not be created.");
Expand Down Expand Up @@ -268,8 +268,8 @@ public void skipNotFoundVideo() throws Exception {
null)),
photosLibraryClient,
executor);
assertEquals("Expected the number of bytes to be 0L.", 0L, length);
assertEquals("Expected executor to have no errors.", 0, executor.getErrors().size());
assertEquals(0L, length,"Expected the number of bytes to be 0L.");
assertEquals(0, executor.getErrors().size(),"Expected executor to have no errors.");
}

@Test
Expand All @@ -294,11 +294,9 @@ public void descriptionOver1kCharactersShouldNotFail() {
String uploadToken = "token";
NewMediaItem newMediaItemResult = googleVideosImporter.buildMediaItem(videoModel, uploadToken);
assertFalse(
"Expected the length of the description to be truncated to 1000 chars.",
(newMediaItemResult.getDescription().length() > 1000));
(newMediaItemResult.getDescription().length() > 1000),"Expected the length of the description to be truncated to 1000 chars.");
assertTrue(
"Expected a truncated description to terminate with \"...\"",
newMediaItemResult.getDescription().endsWith("..."));
newMediaItemResult.getDescription().endsWith("..."),"Expected a truncated description to terminate with \"...\"");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.datatransferproject.datatransfer.google.videos;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static com.google.common.truth.Truth.assertThat;

import java.io.*;
import org.junit.jupiter.api.Test;
Expand All @@ -18,9 +16,9 @@ public void testSerialization() throws IOException, ClassNotFoundException {

ByteArrayInputStream bais = new ByteArrayInputStream(out.toByteArray());
Object readObject = new ObjectInputStream(bais).readObject();
assertThat(readObject, instanceOf(VideoResult.class));
assertThat(readObject).isInstanceOf(VideoResult.class);
VideoResult deserialized = (VideoResult) readObject;
assertThat(deserialized.getId(), equalTo(videoId));
assertThat(deserialized.getBytes(), equalTo(bytes));
assertThat(deserialized.getId()).isEqualTo(videoId);
assertThat(deserialized.getBytes()).isEqualTo(bytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.datatransferproject.transfer.imgur.photos;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;

import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.datatransferproject.transfer.koofr;

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

import com.google.common.collect.ImmutableList;
import java.util.Collection;
import org.datatransferproject.types.common.models.photos.PhotoAlbum;
import org.datatransferproject.types.common.models.photos.PhotoModel;
import org.datatransferproject.types.common.models.photos.PhotosContainerResource;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
public class KoofrTransmogrificationConfigTest {

Expand All @@ -32,21 +33,21 @@ public void testPhotoTitleName() {
PhotoAlbum[] albumsArray = container.getAlbums().toArray(new PhotoAlbum[0]);
PhotoModel[] photosArray = container.getPhotos().toArray(new PhotoModel[0]);

Assert.assertEquals(1, albumsArray.length);
Assert.assertEquals("Album _______________1", albumsArray[0].getName());
assertEquals(1, albumsArray.length);
assertEquals("Album _______________1", albumsArray[0].getName());

Assert.assertEquals(2, photosArray.length);
Assert.assertEquals("pic1_______________.jpg", photosArray[0].getTitle());
Assert.assertEquals("pic2_______________.jpg", photosArray[1].getTitle());
assertEquals(2, photosArray.length);
assertEquals("pic1_______________.jpg", photosArray[0].getTitle());
assertEquals("pic2_______________.jpg", photosArray[1].getTitle());
}

@Test
public void testGetAlbumName() {
KoofrTransmogrificationConfig config = new KoofrTransmogrificationConfig();

Assert.assertEquals("Valid name", config.getAlbumName("Valid name"));
Assert.assertEquals("Album", config.getAlbumName(""));
Assert.assertEquals("Album .", config.getAlbumName("."));
Assert.assertEquals("Album ..", config.getAlbumName(".."));
assertEquals("Valid name", config.getAlbumName("Valid name"));
assertEquals("Album", config.getAlbumName(""));
assertEquals("Album .", config.getAlbumName("."));
assertEquals("Album ..", config.getAlbumName(".."));
}
}

0 comments on commit 296076f

Please sign in to comment.