From 82e3b3261d2fc90d3893df6d417a2828ce5f8ab3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 9 Nov 2014 11:30:57 +0100 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20allow=20a=20=E2=80=9Cpost=20cut?= =?utf8?q?=20off=20length=E2=80=9D=20of=20-1=20anymore.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit To disable post cutting, set “characters to display” to -1, the cut-off length will then be ignored. --- src/main/java/net/pterodactylus/sone/core/Preferences.java | 3 +-- .../java/net/pterodactylus/sone/core/PreferencesLoader.java | 10 +++++++--- .../net/pterodactylus/sone/core/PreferencesLoaderTest.java | 9 +++++++++ src/test/java/net/pterodactylus/sone/core/PreferencesTest.java | 5 +++++ 4 files changed, 22 insertions(+), 5 deletions(-) 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); -- 2.7.4