33import org .javawebstack .orm .Model ;
44import org .javawebstack .orm .ORM ;
55import org .javawebstack .orm .ORMConfig ;
6- import org .javawebstack .orm .annotation .Column ;
76import org .javawebstack .orm .exception .ORMConfigurationException ;
87import org .javawebstack .orm .test .ORMTestCase ;
98import org .javawebstack .orm .test .shared .models .Datatype ;
109import org .javawebstack .orm .test .shared .models .JustCharArray ;
1110import org .javawebstack .orm .test .shared .models .JustString ;
1211import org .javawebstack .orm .test .shared .verification .Field ;
13- import org .junit .jupiter .api .BeforeEach ;
1412import org .junit .jupiter .api .Test ;
1513
1614import java .sql .SQLException ;
1715
16+ import static org .junit .jupiter .api .Assertions .assertThrows ;
17+
1818/**
1919 * This class tests if the default size is being applied for the types:
2020 * - String
2929 * - Float
3030 * - double
3131 * - Double
32+ *
33+ * And covers the following error cases:
34+ * - negative default size has been set
35+ * - zero default size has been set
3236 */
3337public class DefaultSizeTest extends ORMTestCase {
3438
@@ -57,6 +61,11 @@ public class DefaultSizeTest extends ORMTestCase {
5761
5862 final static String tableNameDatatype = "datatypes" ;
5963
64+ /*
65+ * Positive Test
66+ */
67+
68+ // String
6069 @ Test
6170 public void testStringUsesDefaultSizeChar () throws ORMConfigurationException , SQLException {
6271 setUpWithDefaultSize (JustString .class , 1 );
@@ -90,6 +99,7 @@ public void testStringUsesDefaultSizeLongText() throws ORMConfigurationException
9099 }
91100 }
92101
102+ // Char Array
93103 @ Test
94104 public void testCharArrayUsesDefaultSizeChar () throws ORMConfigurationException , SQLException {
95105 setUpWithDefaultSize (JustCharArray .class , 1 );
@@ -123,6 +133,10 @@ public void testCharArrayUsesDefaultSizeLongText() throws ORMConfigurationExcept
123133 }
124134 }
125135
136+ /*
137+ * Negative Tests
138+ */
139+
126140 @ Test
127141 public void testOtherDataTypesDoNotUseDefaultSize () throws ORMConfigurationException , SQLException {
128142 // smallint defaults to the size 6 the default size should therefore not be chosen as 6 or higher;
@@ -147,6 +161,29 @@ public void testOtherDataTypesDoNotUseDefaultSize() throws ORMConfigurationExcep
147161 (new Field (tableNameDatatype , "wrapper_double" )).assertType ("double" );
148162 }
149163
164+ /*
165+ * Error Cases
166+ */
167+
168+ @ Test
169+ public void defaultSizeIsZero () {
170+ assertThrows (
171+ ORMConfigurationException .class ,
172+ () -> new ORMConfig ().setDefaultSize (0 ),
173+ "Registering a class with a default size of 0 must throw an ORMConfigurationException but it didn't."
174+ );
175+ }
176+
177+ @ Test
178+ public void defaultSizeIsNegative () {
179+ assertThrows (
180+ ORMConfigurationException .class ,
181+ () -> setUpWithDefaultSize (JustString .class , -1 ),
182+ "Registering a class with a negative default size must throw an ORMConfigurationException but it didn't."
183+ );
184+ }
185+
186+
150187 private void setUpWithDefaultSize (Class <? extends Model > clazz , int defaultSize ) throws ORMConfigurationException {
151188 ORMConfig config = new ORMConfig ()
152189 .setDefaultSize (defaultSize );
0 commit comments