-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add limits overriding with system properties #112
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package de.siegmar.fastcsv.util; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class LimitsTest { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The two properties ( |
||
|
||
@BeforeEach | ||
void setup() { | ||
System.clearProperty("fastcsv.max.field.size"); | ||
System.clearProperty("fastcsv.max.field.count"); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this is required. Isn't AfterEach sufficient? |
||
|
||
@AfterEach | ||
void cleanup() { | ||
System.clearProperty("fastcsv.max.field.size"); | ||
System.clearProperty("fastcsv.max.field.count"); | ||
} | ||
|
||
@Test | ||
void defaultMaxFieldSize() { | ||
assertEquals(16 * 1024 * 1024, Limits.MAX_FIELD_SIZE, "Default max field size should be correct"); | ||
} | ||
|
||
@Test | ||
void customMaxFieldSize() { | ||
System.setProperty("fastcsv.max.field.size", "100000"); | ||
|
||
assertEquals(100000, Limits.getIntProperty("fastcsv.max.field.size", 16 * 1024 * 1024), | ||
"Custom max field size should be respected"); | ||
} | ||
|
||
@Test | ||
void defaultMaxFieldCount() { | ||
assertEquals(16 * 1024, Limits.MAX_FIELD_COUNT, "Default max field count should be correct"); | ||
} | ||
|
||
@Test | ||
void customMaxFieldCount() { | ||
System.setProperty("fastcsv.max.field.count", "200"); | ||
|
||
assertEquals(200, Limits.getIntProperty("fastcsv.max.field.count", 16 * 1024), | ||
"Custom max field count should be respected"); | ||
} | ||
|
||
@Test | ||
void invalidMaxFieldSizeThrowsException() { | ||
System.setProperty("fastcsv.max.field.size", "invalid"); | ||
|
||
assertThrows(IllegalArgumentException.class, | ||
() -> Limits.getIntProperty("fastcsv.max.field.size", 16 * 1024 * 1024), | ||
"Should throw IllegalArgumentException for invalid integer format"); | ||
} | ||
|
||
@Test | ||
void testMaxRecordSizeBasedOnMaxFieldSize() { | ||
System.setProperty("fastcsv.max.field.size", "4000000"); | ||
|
||
assertEquals(4 * 4000000, | ||
4 * Limits.getIntProperty("fastcsv.max.field.size", 16 * 1024 * 1024), | ||
"MAX_RECORD_SIZE should be four times MAX_FIELD_SIZE"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FastCSV uses AssertJ-Assertions exclusively.