Skip to content

Commit

Permalink
Add doc on the test also
Browse files Browse the repository at this point in the history
  • Loading branch information
JooHyukKim committed Jul 27, 2023
1 parent f6fee2f commit efec88f
Showing 1 changed file with 50 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;

/**
* Unit tests for class {@link ErrorReportConfiguration}.
*
* @since 2.16
*/
public class ErrorReportConfigurationTest
{
private final ErrorReportConfiguration DEFAULTS = ErrorReportConfiguration.defaults();

@Test
public void testMaxErrorTokenLength()
public void testZeroLengths()
{
ErrorReportConfiguration.Builder builder = new ErrorReportConfiguration.Builder();
int maxLength = 128;
builder.maxErrorTokenLength(maxLength);
builder.maxErrorTokenLength(0);
builder.maxRawContentLength(0);
ErrorReportConfiguration config = builder.build();
assertEquals(maxLength, config.getMaxErrorTokenLength());
assertEquals(0, config.getMaxErrorTokenLength());
assertEquals(0, config.getMaxRawContentLength());
}

@Test
Expand Down Expand Up @@ -53,11 +61,9 @@ public void testInvalidMaxRawContentLength()
@Test
public void testDefaults()
{
ErrorReportConfiguration config = ErrorReportConfiguration.defaults();

// default value
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH, config.getMaxErrorTokenLength());
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH, config.getMaxRawContentLength());
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH, DEFAULTS.getMaxErrorTokenLength());
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH, DEFAULTS.getMaxRawContentLength());

// equals
assertEquals(ErrorReportConfiguration.defaults(), ErrorReportConfiguration.defaults());
Expand All @@ -66,23 +72,26 @@ public void testDefaults()
@Test
public void testOverrideDefaultErrorReportConfiguration()
{
// try override static
ErrorReportConfiguration newConfig = new ErrorReportConfiguration.Builder()
// try with null, no change
ErrorReportConfiguration nullDefaults = ErrorReportConfiguration.defaults();
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(null);
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH, nullDefaults.getMaxErrorTokenLength());
assertEquals(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH, nullDefaults.getMaxRawContentLength());

// try override defaults
ErrorReportConfiguration overrideDefaults = new ErrorReportConfiguration.Builder()
.maxErrorTokenLength(128)
.maxRawContentLength(256)
.build();
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(newConfig);

ErrorReportConfiguration config = ErrorReportConfiguration.defaults();
assertEquals(128, config.getMaxErrorTokenLength());
assertEquals(256, config.getMaxRawContentLength());
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(overrideDefaults);
assertEquals(128, overrideDefaults.getMaxErrorTokenLength());
assertEquals(256, overrideDefaults.getMaxRawContentLength());

// IMPORTANT : make sure to revert back, otherwise other tests will be affected
ErrorReportConfiguration defaultConfig = new ErrorReportConfiguration.Builder()
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(new ErrorReportConfiguration.Builder()
.maxErrorTokenLength(ErrorReportConfiguration.DEFAULT_MAX_ERROR_TOKEN_LENGTH)
.maxRawContentLength(ErrorReportConfiguration.DEFAULT_MAX_RAW_CONTENT_LENGTH)
.build();
ErrorReportConfiguration.overrideDefaultErrorReportConfiguration(defaultConfig);
.build());
}

@Test
Expand All @@ -93,4 +102,27 @@ public void testRebuild()
assertEquals(config.getMaxErrorTokenLength(), rebuiltConfig.getMaxErrorTokenLength());
assertEquals(config.getMaxRawContentLength(), rebuiltConfig.getMaxRawContentLength());
}


@Test
public void testBuilderConstructorWithTwoParams()
{
ErrorReportConfiguration.Builder builder = new ErrorReportConfiguration.Builder(128, 256);
ErrorReportConfiguration config = builder.build();
assertEquals(128, config.getMaxErrorTokenLength());
assertEquals(256, config.getMaxRawContentLength());
}

@Test
public void testBuilderConstructorWithErrorReportConfiguration()
{
ErrorReportConfiguration newConfig = new ErrorReportConfiguration.Builder()
.maxErrorTokenLength(128)
.maxRawContentLength(256)
.build();
ErrorReportConfiguration.Builder builder = new ErrorReportConfiguration.Builder(newConfig);
ErrorReportConfiguration config = builder.build();
assertEquals(newConfig.getMaxErrorTokenLength(), config.getMaxErrorTokenLength());
assertEquals(newConfig.getMaxRawContentLength(), config.getMaxRawContentLength());
}
}

0 comments on commit efec88f

Please sign in to comment.