Add method to set the value of a field.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 23 Oct 2013 05:08:22 +0000 (07:08 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:34 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/data/Profile.java
src/test/java/net/pterodactylus/sone/data/ProfileTest.java

index 0b30f83..898deb6 100644 (file)
@@ -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
index eab4062..0fcb80e 100644 (file)
@@ -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"));
+       }
+
 }