From: David ‘Bombe’ Roden Date: Sun, 9 Nov 2014 10:30:57 +0000 (+0100) Subject: Don’t allow a “post cut off length” of -1 anymore. X-Git-Tag: 0.9-rc1^2~3^2~32 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=82e3b3261d2fc90d3893df6d417a2828ce5f8ab3;p=Sone.git Don’t allow a “post cut off length” of -1 anymore. To disable post cutting, set “characters to display” to -1, the cut-off length will then be ignored. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Preferences.java b/src/main/java/net/pterodactylus/sone/core/Preferences.java index f7ecdab..56bfa73 100644 --- a/src/main/java/net/pterodactylus/sone/core/Preferences.java +++ b/src/main/java/net/pterodactylus/sone/core/Preferences.java @@ -55,8 +55,7 @@ public class Preferences { new DefaultOption(400, Predicates.or( range(50, MAX_VALUE), equalTo(-1))); private final Option postCutOffLength = - new DefaultOption(200, Predicates.or( - range(50, MAX_VALUE), equalTo(-1))); + new DefaultOption(200, range(50, MAX_VALUE)); private final Option requireFullAccess = new DefaultOption(false); private final Option positiveTrust = diff --git a/src/main/java/net/pterodactylus/sone/core/PreferencesLoader.java b/src/main/java/net/pterodactylus/sone/core/PreferencesLoader.java index 6cc2e5e..0ae13ba 100644 --- a/src/main/java/net/pterodactylus/sone/core/PreferencesLoader.java +++ b/src/main/java/net/pterodactylus/sone/core/PreferencesLoader.java @@ -56,9 +56,13 @@ public class PreferencesLoader { } private void loadPostCutOffLength(Configuration configuration) { - preferences.setPostCutOffLength( - configuration.getIntValue("Option/PostCutOffLength") - .getValue(null)); + try { + preferences.setPostCutOffLength( + configuration.getIntValue("Option/PostCutOffLength") + .getValue(null)); + } catch (IllegalArgumentException iae1) { + /* previous versions allowed -1, ignore and use default. */ + } } private void loadRequireFullAccess(Configuration configuration) { diff --git a/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java b/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java index 91120fb..88745df 100644 --- a/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java +++ b/src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java @@ -3,6 +3,7 @@ package net.pterodactylus.sone.core; import static net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -70,4 +71,12 @@ public class PreferencesLoaderTest { assertThat(preferences.getFcpFullAccessRequired(), is(WRITING)); } + @Test + public void configurationIsLoadedCorrectlyWithCutOffLengthMinusOne() { + setupConfiguration(); + setupIntValue("PostCutOffLength", -1); + preferencesLoader.loadFrom(configuration); + assertThat(preferences.getPostCutOffLength(), not(is(-1))); + } + } diff --git a/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java b/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java index cfa3495..a19fe2e 100644 --- a/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java +++ b/src/test/java/net/pterodactylus/sone/core/PreferencesTest.java @@ -137,6 +137,11 @@ public class PreferencesTest { preferences.setPostCutOffLength(-15); } + @Test(expected = IllegalArgumentException.class) + public void cutOffLengthOfMinusOneIsNotAllowed() { + preferences.setPostCutOffLength(-1); + } + @Test public void preferencesReturnDefaultValueWhenPostCutOffLengthIsSetToNull() { preferences.setPostCutOffLength(null);