diff options
| -rw-r--r-- | main/src/cgeo/geocaching/PersonalNote.java | 14 | ||||
| -rw-r--r-- | tests/src/cgeo/geocaching/PersonalNoteTest.java | 16 |
2 files changed, 12 insertions, 18 deletions
diff --git a/main/src/cgeo/geocaching/PersonalNote.java b/main/src/cgeo/geocaching/PersonalNote.java index 3413307..82e88f7 100644 --- a/main/src/cgeo/geocaching/PersonalNote.java +++ b/main/src/cgeo/geocaching/PersonalNote.java @@ -4,8 +4,7 @@ import org.apache.commons.lang3.StringUtils; public class PersonalNote { - private static final String MERGED_PREFIX = "merged:\n"; - private static final String SEPARATOR = "--\n"; + private static final String SEPARATOR = "\n--\n"; private String cgeoNote; private String providerNote; private boolean isOffline; @@ -15,23 +14,18 @@ public class PersonalNote { } public PersonalNote(final Geocache cache) { + this.isOffline = cache.isOffline(); final String personalNote = cache.getPersonalNote(); - if (!StringUtils.startsWith(personalNote, MERGED_PREFIX)) { - this.providerNote = personalNote; + if (StringUtils.isEmpty(personalNote)) { return; } final String[] notes = StringUtils.splitByWholeSeparator(personalNote, SEPARATOR); - if (notes.length > 0) { - notes[0] = StringUtils.removeStart(notes[0], MERGED_PREFIX); - notes[0] = StringUtils.removeEnd(notes[0], "\n"); - } if (notes.length > 1) { this.cgeoNote = notes[0]; this.providerNote = notes[1]; } else { this.providerNote = notes[0]; } - this.isOffline = cache.isOffline(); } public final PersonalNote mergeWith(final PersonalNote other) { @@ -95,7 +89,7 @@ public class PersonalNote { public final String toString() { final StringBuilder builder = new StringBuilder(); if (cgeoNote != null) { - builder.append(MERGED_PREFIX).append(cgeoNote).append("\n").append(SEPARATOR); + builder.append(cgeoNote).append(SEPARATOR); } builder.append(providerNote); return builder.toString(); diff --git a/tests/src/cgeo/geocaching/PersonalNoteTest.java b/tests/src/cgeo/geocaching/PersonalNoteTest.java index fd185ed..c8aa8ba 100644 --- a/tests/src/cgeo/geocaching/PersonalNoteTest.java +++ b/tests/src/cgeo/geocaching/PersonalNoteTest.java @@ -5,7 +5,7 @@ import junit.framework.TestCase; public class PersonalNoteTest extends TestCase { public static void testParse() { - final String testString = "merged:\nSimple cgeo note\n--\nSimple provider note"; + final String testString = "Simple cgeo note\n--\nSimple provider note"; Geocache cache = new Geocache(); cache.setPersonalNote(testString); PersonalNote parsedNote = new PersonalNote(cache); @@ -24,7 +24,7 @@ public class PersonalNoteTest extends TestCase { } public static void testParseCgeoOnly() { - final String testString = "merged:\nSimple cgeo note"; + final String testString = "Simple cgeo note"; Geocache cache = new Geocache(); cache.setPersonalNote(testString); PersonalNote parsedNote = new PersonalNote(cache); @@ -34,30 +34,30 @@ public class PersonalNoteTest extends TestCase { public static void testSimpleMerge() { Geocache cache1 = new Geocache(); // not stored - cache1.setPersonalNote("merged:\nSimple cgeo note\n--\nSimple provider note"); + cache1.setPersonalNote("Simple cgeo note\n--\nSimple provider note"); PersonalNote myNote = new PersonalNote(cache1); Geocache cache2 = new Geocache(); cache2.setListId(StoredList.STANDARD_LIST_ID); // stored - cache2.setPersonalNote("merged:\ncgeo note\n--\nProvider note"); + cache2.setPersonalNote("cgeo note\n--\nProvider note"); PersonalNote otherNote = new PersonalNote(cache2); PersonalNote result = myNote.mergeWith(otherNote); - assertEquals("merged:\ncgeo note\n--\nSimple provider note", result.toString()); + assertEquals("cgeo note\n--\nSimple provider note", result.toString()); assertPersonalNote(result, "cgeo note", "Simple provider note"); } public static void testMixedMerge() { Geocache cache1 = new Geocache(); // not stored - cache1.setPersonalNote("merged:\nSimple cgeo note\n--\nSimple provider note"); + cache1.setPersonalNote("Simple cgeo note\n--\nSimple provider note"); PersonalNote myNote = new PersonalNote(cache1); Geocache cache2 = new Geocache(); cache2.setListId(StoredList.STANDARD_LIST_ID); // stored cache2.setPersonalNote("Provider note"); PersonalNote otherNote = new PersonalNote(cache2); PersonalNote result = myNote.mergeWith(otherNote); - assertEquals("merged:\nSimple cgeo note\n--\nSimple provider note", result.toString()); + assertEquals("Simple cgeo note\n--\nSimple provider note", result.toString()); assertPersonalNote(result, "Simple cgeo note", "Simple provider note"); result = otherNote.mergeWith(myNote); - assertEquals("merged:\nSimple cgeo note\n--\nProvider note", result.toString()); + assertEquals("Simple cgeo note\n--\nProvider note", result.toString()); assertPersonalNote(result, "Simple cgeo note", "Provider note"); } |
