From a31fadee57ce42f013454da35282d44477edfbca Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 24 Oct 2013 07:18:30 +0200 Subject: [PATCH] Add more tests. --- .../net/pterodactylus/sone/data/ProfileTest.java | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/test/java/net/pterodactylus/sone/data/ProfileTest.java b/src/test/java/net/pterodactylus/sone/data/ProfileTest.java index a4e70c0..66aa568 100644 --- a/src/test/java/net/pterodactylus/sone/data/ProfileTest.java +++ b/src/test/java/net/pterodactylus/sone/data/ProfileTest.java @@ -18,15 +18,19 @@ package net.pterodactylus.sone.data; import static com.google.common.base.Optional.of; +import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; import java.util.List; import net.pterodactylus.sone.data.Profile.Field; import com.google.common.base.Optional; +import com.google.common.collect.Lists; import org.junit.Test; /** @@ -193,4 +197,56 @@ public class ProfileTest { assertThat(profile.getAvatar(), is((String) null)); } + @Test + public void testDuplicatingAProfileAndGettingTheSameFingerprint() { + Profile secondProfile = new Profile(profile); + assertThat(profile.getFingerprint(), is(secondProfile.getFingerprint())); + } + + @Test + public void testGettingAFingerprint() { + String fingerprint = profile.getFingerprint(); + assertThat(fingerprint, notNullValue()); + } + + @Test + public void testThatSettingProfileFieldsChangesTheFingerprint() { + List fingerprints = Lists.newArrayList(); + String fingerprint = profile.getFingerprint(); + assertThat(fingerprint, notNullValue()); + fingerprints.add(fingerprint); + + Field testField = profile.addField("TestField"); + profile.setField(testField, "Value"); + verifyFingerprintAndAddItToListOfFingerprints(fingerprints); + + profile.modify().setFirstName("First").update(); + verifyFingerprintAndAddItToListOfFingerprints(fingerprints); + + profile.modify().setMiddleName("M.").update(); + verifyFingerprintAndAddItToListOfFingerprints(fingerprints); + + profile.modify().setLastName("Last").update(); + verifyFingerprintAndAddItToListOfFingerprints(fingerprints); + + profile.modify().setBirthYear(2013).update(); + verifyFingerprintAndAddItToListOfFingerprints(fingerprints); + + profile.modify().setBirthMonth(10).update(); + verifyFingerprintAndAddItToListOfFingerprints(fingerprints); + + profile.modify().setBirthDay(24).update(); + verifyFingerprintAndAddItToListOfFingerprints(fingerprints); + + profile.setAvatar(of("avatar1")); + verifyFingerprintAndAddItToListOfFingerprints(fingerprints); + } + + private void verifyFingerprintAndAddItToListOfFingerprints(List fingerprints) { + String fingerprint = profile.getFingerprint(); + assertThat(fingerprint, notNullValue()); + assertThat(fingerprints, not(hasItem(fingerprint))); + fingerprints.add(fingerprint); + } + } -- 2.7.4