Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made GoogleAlbum serializable; added test to check serializability #1279

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package org.datatransferproject.datatransfer.google.mediaModels;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;

/**
* Class representing an album as returned by the Google Photos API.
*/
public class GoogleAlbum {
public class GoogleAlbum implements Serializable {
@JsonProperty("id")
private String id;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.datatransferproject.datatransfer.google.mediaModels;

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

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import org.datatransferproject.types.common.models.photos.PhotoModel;
import org.datatransferproject.types.common.models.videos.VideoModel;
import org.junit.Test;
public class GoogleAlbumTest {
private static final ObjectMapper mapper = new ObjectMapper()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);

@Test
public void googleAlbum_isSerializable() {
String googleAlbumStringJSON = "{\"id\":\"test_id\", \"title\":\"test_title\", \"isWriteable\":true, \"mediaItemsCount\":10}";
boolean serializable = true;
// Turning an object into a byte array can only be done if the class is serializable.
try {
GoogleAlbum googleAlbum = mapper.readValue(googleAlbumStringJSON, GoogleAlbum.class);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(googleAlbum);
oos.flush();
byte [] data = bos.toByteArray();
} catch (Exception e ) {
serializable = false;
}
assertTrue(serializable);
}

}