Don’t allow a “post cut off length” of -1 anymore.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 9 Nov 2014 10:30:57 +0000 (11:30 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 22 Nov 2014 11:37:59 +0000 (12:37 +0100)
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
src/main/java/net/pterodactylus/sone/core/PreferencesLoader.java
src/test/java/net/pterodactylus/sone/core/PreferencesLoaderTest.java
src/test/java/net/pterodactylus/sone/core/PreferencesTest.java

index f7ecdab..56bfa73 100644 (file)
@@ -55,8 +55,7 @@ public class Preferences {
                        new DefaultOption<Integer>(400, Predicates.<Integer>or(
                                        range(50, MAX_VALUE), equalTo(-1)));
        private final Option<Integer> postCutOffLength =
-                       new DefaultOption<Integer>(200, Predicates.<Integer>or(
-                                       range(50, MAX_VALUE), equalTo(-1)));
+                       new DefaultOption<Integer>(200, range(50, MAX_VALUE));
        private final Option<Boolean> requireFullAccess =
                        new DefaultOption<Boolean>(false);
        private final Option<Integer> positiveTrust =
index 6cc2e5e..0ae13ba 100644 (file)
@@ -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) {
index 91120fb..88745df 100644 (file)
@@ -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)));
+       }
+
 }
index cfa3495..a19fe2e 100644 (file)
@@ -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);