From 745511cbc455604bb9ecbad3f6a2ea84e789de05 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 23 Oct 2013 07:08:22 +0200 Subject: [PATCH] Add method to set the value of a field. --- src/main/java/net/pterodactylus/sone/data/Profile.java | 8 ++++++++ src/test/java/net/pterodactylus/sone/data/ProfileTest.java | 9 +++++++++ 2 files changed, 17 insertions(+) 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")); + } + } -- 2.7.4