Skip to content

Commit 7330e08

Browse files
committed
PrefServiceTest: add a test for keys >80 chars
The Java Preferences API does not support these; let's make sure they (largely) work anyway.
1 parent 39e3b21 commit 7330e08

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/java/org/scijava/prefs/PrefServiceTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,24 @@ public void testList() {
175175
assertEquals(recentFiles, result);
176176
}
177177

178+
/**
179+
* The Java Preferences API does not support keys longer than 80 characters.
180+
* Let's test that our service does not fall victim to this limitation.
181+
*/
182+
@Test
183+
public void testLongKeys() {
184+
final String longKey = "" + //
185+
"abcdefghijklmnopqrstuvwxyz" + //
186+
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + //
187+
"0123456789" + //
188+
"9876543210" + //
189+
"ZYXWVUTSRQPONMLKJIHGFEDCBA" + //
190+
"zyxwvutsrqponmlkjihgfedcba";
191+
final String lyrics =
192+
"Now I know my ABC's. Next time won't you sing with me?";
193+
prefService.put(longKey, lyrics);
194+
final String recovered = prefService.get(longKey);
195+
assertEquals(lyrics, recovered);
196+
}
197+
178198
}

0 commit comments

Comments
 (0)