From 7358efe1d078075cd649b7654b9ba1669d3a8e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Thu, 21 Apr 2022 09:08:45 +0200 Subject: [PATCH] feat: first basic test --- build.gradle | 7 +++-- src/main/java/com/pixels/beans/Pixel.java | 5 ++-- src/test/java/com/pixels/beans/PixelTest.java | 28 +++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/pixels/beans/PixelTest.java diff --git a/build.gradle b/build.gradle index 6158cdf..ba78171 100644 --- a/build.gradle +++ b/build.gradle @@ -23,8 +23,11 @@ dependencies { // Pour pouvoir parser le JSON implementation 'com.google.code.gson:gson:2.8.6' - implementation 'org.hibernate:hibernate-core:5.4.30.Final' - implementation 'mysql:mysql-connector-java:8.0.24' + // implementation 'org.hibernate:hibernate-core:5.4.30.Final' + // implementation 'mysql:mysql-connector-java:8.0.24' + + // des fonctions pratiques + implementation 'org.apache.commons:commons-lang3:3.0' // Pour les tests testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2' diff --git a/src/main/java/com/pixels/beans/Pixel.java b/src/main/java/com/pixels/beans/Pixel.java index 5499b7b..1cba073 100644 --- a/src/main/java/com/pixels/beans/Pixel.java +++ b/src/main/java/com/pixels/beans/Pixel.java @@ -107,8 +107,9 @@ public class Pixel implements Serializable { return false; } Pixel pixel = (Pixel) o; - return id.equals(pixel.id) && price == pixel.price && color == pixel.color - && description.equals(pixel.description) && owner.equals(pixel.owner); + return Objects.equals(id, pixel.id) && price == pixel.price && color == pixel.color + && Objects.equals(description, pixel.description) && Objects.equals(owner, pixel.owner) + && Objects.equals(transactions, pixel.transactions); } @Override diff --git a/src/test/java/com/pixels/beans/PixelTest.java b/src/test/java/com/pixels/beans/PixelTest.java new file mode 100644 index 0000000..dbde338 --- /dev/null +++ b/src/test/java/com/pixels/beans/PixelTest.java @@ -0,0 +1,28 @@ +package com.pixels.beans; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.apache.commons.lang3.SerializationUtils; + +public class PixelTest { + + private static Pixel pixel; + + @BeforeAll + public static void setUp() throws Exception { + pixel = new Pixel(); + pixel.setId(123456789L); + pixel.setPrice(10); + } + + @Test + public void beanIsSerializable() { + final byte[] serializedPixel = SerializationUtils.serialize(pixel); + final Pixel deserializedPixel = (Pixel) SerializationUtils.deserialize(serializedPixel); + assertEquals(pixel, deserializedPixel); + } + +}