From 938ccca9fe251dc3b0dfb881c6e7ae22c3ce0207 Mon Sep 17 00:00:00 2001 From: Valeriy Vyrva Date: Fri, 28 Oct 2022 11:11:24 +0300 Subject: [PATCH] Allow generate string of size 0 --- .../net/andreinc/mockneat/unit/text/Strings.java | 2 +- .../net/andreinc/mockneat/utils/ValidationUtils.java | 1 - .../net/andreinc/mockneat/unit/text/StringsTest.java | 12 ++++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/andreinc/mockneat/unit/text/Strings.java b/src/main/java/net/andreinc/mockneat/unit/text/Strings.java index 1a5e49d..d197024 100644 --- a/src/main/java/net/andreinc/mockneat/unit/text/Strings.java +++ b/src/main/java/net/andreinc/mockneat/unit/text/Strings.java @@ -36,7 +36,7 @@ public Strings(MockNeat mockNeat) { } public Strings size(int size) { - isTrue(size>0, SIZE_BIGGER_THAN_ZERO_STRICT); + isTrue(size>=0, SIZE_BIGGER_THAN_ZERO); this.size = size; return this; } diff --git a/src/main/java/net/andreinc/mockneat/utils/ValidationUtils.java b/src/main/java/net/andreinc/mockneat/utils/ValidationUtils.java index 0e3517d..3f66189 100644 --- a/src/main/java/net/andreinc/mockneat/utils/ValidationUtils.java +++ b/src/main/java/net/andreinc/mockneat/utils/ValidationUtils.java @@ -35,7 +35,6 @@ public final class ValidationUtils { public static final String UPPER_BOUND_BIGGER_LOWER_BOUND = "The input parameter 'upperBound' > 'lowerBound'."; public static final String UPPER_MONTH_BIGGER_THAN_LOWER = "'lower' Month < 'upper' Month"; public static final String IS_FINITE_NUMBER = "Number #{number} should be finite (non-infinite, non-nan)."; - public static final String SIZE_BIGGER_THAN_ZERO_STRICT = "The size needs to be bigger than 0 (>)."; public static final String SIZE_BIGGER_THAN_ZERO = "The size needs to be bigger than 0 (>=)."; public static final String IN_RANGE_CLOSED = "Number: #{num} should be in [#{min}, #{max}] range."; public static final String CANNOT_ADD_VALUE_TO_COLLECTION = "Cannot add value '#{val}' to collection '#{cls.simpleName}'"; diff --git a/src/test/java/net/andreinc/mockneat/unit/text/StringsTest.java b/src/test/java/net/andreinc/mockneat/unit/text/StringsTest.java index 3bd8e79..c5580fb 100644 --- a/src/test/java/net/andreinc/mockneat/unit/text/StringsTest.java +++ b/src/test/java/net/andreinc/mockneat/unit/text/StringsTest.java @@ -22,6 +22,18 @@ public void testSizeNegative() { M.strings().size(-10).val(); } + @Test + public void testSizeZero() { + loop( + 1, + MOCKS, + (m) -> { + String empty = m.strings().size(0).val(); + assertEquals(0, empty.length()); + } + ); + } + @Test public void testVariableSizes() { loop(