Add tests for missing and empty profiles.
[Sone.git] / src / test / java / net / pterodactylus / sone / core / SoneParserTest.java
index b0d553d..16fa99e 100644 (file)
@@ -3,10 +3,12 @@ package net.pterodactylus.sone.core;
 import static com.google.common.base.Objects.equal;
 import static java.lang.String.format;
 import static java.util.logging.Level.OFF;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.notNullValue;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
 import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
 import static org.mockito.Matchers.anyString;
 import static org.mockito.Mockito.mock;
@@ -91,6 +93,24 @@ public class SoneParserTest {
                assertThat(sone.getClient(), is(originalSone.getClient()));
        }
 
+       @Test(expected = MalformedXml.class)
+       public void verifyThatAMissingProfileCausesAnError() {
+               soneParser.parseSone(database, originalSone, getXml("missing-profile"));
+       }
+
+       @Test
+       public void verifyThatAnEmptyProfileIsParsedWithoutError() {
+               Sone sone = soneParser.parseSone(database, originalSone, getXml("empty-profile"));
+               assertThat(sone.getProfile().getFirstName(), nullValue());
+               assertThat(sone.getProfile().getMiddleName(), nullValue());
+               assertThat(sone.getProfile().getLastName(), nullValue());
+               assertThat(sone.getProfile().getBirthYear(), nullValue());
+               assertThat(sone.getProfile().getBirthMonth(), nullValue());
+               assertThat(sone.getProfile().getBirthDay(), nullValue());
+               assertThat(sone.getProfile().getAvatar(), nullValue());
+               assertThat(sone.getProfile().getFields(), empty());
+       }
+
        @Test
        public void verifyThatTheCreatedSoneMeetsAllExpectations() {
                Sone sone = soneParser.parseSone(database, originalSone, getXml("complete"));