Add more tests.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 24 Oct 2013 05:18:30 +0000 (07:18 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:35 +0000 (22:25 +0100)
src/test/java/net/pterodactylus/sone/data/ProfileTest.java

index a4e70c0..66aa568 100644 (file)
 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<String> 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<String> fingerprints) {
+               String fingerprint = profile.getFingerprint();
+               assertThat(fingerprint, notNullValue());
+               assertThat(fingerprints, not(hasItem(fingerprint)));
+               fingerprints.add(fingerprint);
+       }
+
 }