From: David ‘Bombe’ Roden Date: Wed, 23 Oct 2013 05:08:22 +0000 (+0200) Subject: Add method to set the value of a field. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=745511cbc455604bb9ecbad3f6a2ea84e789de05;p=Sone.git Add method to set the value of a field. --- diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 0b30f83..898deb6 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -246,6 +246,14 @@ public class Profile implements Fingerprintable { fields.set(indexOfField, new Field(field.getId(), newName, field.getValue())); } + public void setField(Field field, String newValue) { + int indexOfField = getFieldIndex(field); + if (indexOfField == -1) { + return; + } + fields.get(indexOfField).setValue(newValue); + } + /** * Moves the given field up one position in the field list. The index of the * field to move must be greater than {@code 0} (because you obviously can diff --git a/src/test/java/net/pterodactylus/sone/data/ProfileTest.java b/src/test/java/net/pterodactylus/sone/data/ProfileTest.java index eab4062..0fcb80e 100644 --- a/src/test/java/net/pterodactylus/sone/data/ProfileTest.java +++ b/src/test/java/net/pterodactylus/sone/data/ProfileTest.java @@ -51,4 +51,13 @@ public class ProfileTest { assertThat(testField.getId(), is(renamedField.getId())); } + @Test + public void testChangingTheValueOfAField() { + profile.addField("TestField"); + Field testField = profile.getFieldByName("TestField"); + profile.setField(testField, "Test"); + testField = profile.getFieldByName("TestField"); + assertThat(testField.getValue(), is("Test")); + } + }