From e0e458c6bafa1bdeab29a27567e48e22b5884d51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 24 Oct 2013 06:54:48 +0200 Subject: [PATCH] Add lots of tests for the profile. --- .../net/pterodactylus/sone/data/ProfileTest.java | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/src/test/java/net/pterodactylus/sone/data/ProfileTest.java b/src/test/java/net/pterodactylus/sone/data/ProfileTest.java index 37a2ad6..33d7fff 100644 --- a/src/test/java/net/pterodactylus/sone/data/ProfileTest.java +++ b/src/test/java/net/pterodactylus/sone/data/ProfileTest.java @@ -18,8 +18,11 @@ package net.pterodactylus.sone.data; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; +import java.util.List; + import net.pterodactylus.sone.data.Profile.Field; import com.google.common.base.Optional; @@ -43,6 +46,34 @@ public class ProfileTest { } @Test + public void testGettingAFieldByName() { + profile.addField("TestField"); + Optional testField = profile.getFieldByName("TestField"); + assertThat(testField.isPresent(), is(true)); + } + + @Test + public void testGettingANonExistingFieldByName() { + profile.addField("TestField"); + Optional testField = profile.getFieldByName("TestField2"); + assertThat(testField.isPresent(), is(false)); + } + + @Test + public void testGettingAFieldById() { + profile.addField("TestField"); + Optional testField = profile.getFieldByName("TestField"); + testField = profile.getFieldById(testField.get().getId()); + assertThat(testField.isPresent(), is(true)); + } + + @Test + public void testGettingANonExistingFieldById() { + Optional testField = profile.getFieldById("does not exist"); + assertThat(testField.isPresent(), is(false)); + } + + @Test public void testRenamingAField() { profile.addField("TestField"); Optional testField = profile.getFieldByName("TestField"); @@ -52,6 +83,15 @@ public class ProfileTest { } @Test + public void testRenamingANonExistingField() { + Field testField = profile.addField("TestField"); + profile.removeField(testField); + profile.renameField(testField, "TestField2"); + Optional testField2 = profile.getFieldByName("TestField2"); + assertThat(testField2.isPresent(), is(false)); + } + + @Test public void testChangingTheValueOfAField() { profile.addField("TestField"); Optional testField = profile.getFieldByName("TestField"); @@ -60,4 +100,77 @@ public class ProfileTest { assertThat(testField.get().getValue(), is("Test")); } + @Test + public void testChangingTheValueOfANonExistingField() { + Field testField = profile.addField("TestField"); + profile.removeField(testField); + profile.setField(testField, "Test"); + Optional testField2 = profile.getFieldByName("TestField"); + assertThat(testField2.isPresent(), is(false)); + } + + @Test + public void testDeletingAField() { + profile.addField("TestField"); + Optional testField = profile.getFieldByName("TestField"); + profile.removeField(testField.get()); + testField = profile.getFieldByName("TestField"); + assertThat(testField.isPresent(), is(false)); + } + + @Test + public void testGettingFieldList() { + Field firstField = profile.addField("First"); + Field secondField = profile.addField("Second"); + List fields = profile.getFields(); + assertThat(fields, contains(firstField, secondField)); + } + + @Test + public void testMovingAFieldUp() { + Field firstField = profile.addField("First"); + Field secondField = profile.addField("Second"); + profile.moveFieldUp(secondField); + List fields = profile.getFields(); + assertThat(fields, contains(secondField, firstField)); + } + + @Test + public void testMovingTheFirstFieldUp() { + Field firstField = profile.addField("First"); + Field secondField = profile.addField("Second"); + profile.moveFieldUp(firstField); + List fields = profile.getFields(); + assertThat(fields, contains(firstField, secondField)); + } + + @Test + public void testMovingAFieldDown() { + Field firstField = profile.addField("First"); + Field secondField = profile.addField("Second"); + profile.moveFieldDown(firstField); + List fields = profile.getFields(); + assertThat(fields, contains(secondField, firstField)); + } + + @Test + public void testMovingTheLastFieldDown() { + Field firstField = profile.addField("First"); + Field secondField = profile.addField("Second"); + profile.moveFieldDown(secondField); + List fields = profile.getFields(); + assertThat(fields, contains(firstField, secondField)); + } + + @Test + public void testModifyingAProfile() { + profile.modify().setFirstName("First").setMiddleName("M.").setLastName("Last").setBirthYear(2013).setBirthMonth(10).setBirthDay(24).update(); + assertThat(profile.getFirstName(), is("First")); + assertThat(profile.getMiddleName(), is("M.")); + assertThat(profile.getLastName(), is("Last")); + assertThat(profile.getBirthYear(), is(2013)); + assertThat(profile.getBirthMonth(), is(10)); + assertThat(profile.getBirthDay(), is(24)); + } + } -- 2.7.4