Skip to content
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

Cleanup test classes #562

Merged
merged 3 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TestHttpCacheEntry {
class TestHttpCacheEntry {

private Instant now;
private Instant elevenSecondsAgo;
Expand All @@ -65,7 +65,7 @@ public class TestHttpCacheEntry {
private HttpCacheEntry entry;

@BeforeEach
public void setUp() {
void setUp() {
now = Instant.now();
elevenSecondsAgo = now.minusSeconds(11);
nineSecondsAgo = now.minusSeconds(9);
Expand Down Expand Up @@ -99,23 +99,23 @@ private HttpCacheEntry makeEntry(final Instant requestDate,
}

@Test
public void testGetHeadersReturnsCorrectHeaders() {
void testGetHeadersReturnsCorrectHeaders() {
entry = makeEntry(
new BasicHeader("bar", "barValue1"),
new BasicHeader("bar", "barValue2"));
assertEquals(2, entry.getHeaders("bar").length);
}

@Test
public void testGetFirstHeaderReturnsCorrectHeader() {
void testGetFirstHeaderReturnsCorrectHeader() {
entry = makeEntry(
new BasicHeader("bar", "barValue1"),
new BasicHeader("bar", "barValue2"));
assertEquals("barValue1", entry.getFirstHeader("bar").getValue());
}

@Test
public void testGetHeadersReturnsEmptyArrayIfNoneMatch() {
void testGetHeadersReturnsEmptyArrayIfNoneMatch() {
entry = makeEntry(
new BasicHeader("foo", "fooValue"),
new BasicHeader("bar", "barValue1"),
Expand All @@ -124,7 +124,7 @@ public void testGetHeadersReturnsEmptyArrayIfNoneMatch() {
}

@Test
public void testGetFirstHeaderReturnsNullIfNoneMatch() {
void testGetFirstHeaderReturnsNullIfNoneMatch() {
entry = makeEntry(
new BasicHeader("foo", "fooValue"),
new BasicHeader("bar", "barValue1"),
Expand All @@ -133,7 +133,7 @@ public void testGetFirstHeaderReturnsNullIfNoneMatch() {
}

@Test
public void testGetMethodReturnsCorrectRequestMethod() {
void testGetMethodReturnsCorrectRequestMethod() {
entry = makeEntry(
new BasicHeader("foo", "fooValue"),
new BasicHeader("bar", "barValue1"),
Expand All @@ -142,33 +142,33 @@ public void testGetMethodReturnsCorrectRequestMethod() {
}

@Test
public void statusCodeComesFromOriginalStatusLine() {
void statusCodeComesFromOriginalStatusLine() {
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
assertEquals(HttpStatus.SC_OK, entry.getStatus());
}

@Test
public void canGetOriginalRequestDate() {
void canGetOriginalRequestDate() {
final Instant requestDate = Instant.now();
entry = makeEntry(requestDate, Instant.now(), HttpStatus.SC_OK);
assertEquals(requestDate, entry.getRequestInstant());
}

@Test
public void canGetOriginalResponseDate() {
void canGetOriginalResponseDate() {
final Instant responseDate = Instant.now();
entry = makeEntry(Instant.now(), responseDate, HttpStatus.SC_OK);
assertEquals(responseDate, entry.getResponseInstant());
}

@Test
public void canGetOriginalResource() {
void canGetOriginalResource() {
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
assertSame(mockResource, entry.getResource());
}

@Test
public void canGetOriginalHeaders() {
void canGetOriginalHeaders() {
final Header[] headers = {
new BasicHeader("Server", "MockServer/1.0"),
new BasicHeader("Date", DateUtils.formatStandardDate(now))
Expand All @@ -182,7 +182,7 @@ public void canGetOriginalHeaders() {
}

@Test
public void canRetrieveOriginalVariantMap() {
void canRetrieveOriginalVariantMap() {
final Set<String> variants = new HashSet<>();
variants.add("A");
variants.add("B");
Expand All @@ -199,7 +199,7 @@ public void canRetrieveOriginalVariantMap() {
}

@Test
public void retrievedVariantMapIsNotModifiable() {
void retrievedVariantMapIsNotModifiable() {
final Set<String> variants = new HashSet<>();
variants.add("A");
variants.add("B");
Expand All @@ -213,27 +213,27 @@ public void retrievedVariantMapIsNotModifiable() {
}

@Test
public void canConvertToString() {
void canConvertToString() {
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
assertNotNull(entry.toString());
assertNotEquals("", entry.toString());
}

@Test
public void testMissingDateHeaderIsIgnored() {
void testMissingDateHeaderIsIgnored() {
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK);
assertNull(entry.getInstant());
}

@Test
public void testMalformedDateHeaderIsIgnored() {
void testMalformedDateHeaderIsIgnored() {
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
new BasicHeader("Date", "asdf"));
assertNull(entry.getInstant());
}

@Test
public void testValidDateHeaderIsParsed() {
void testValidDateHeaderIsParsed() {
final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
new BasicHeader("Date", DateUtils.formatStandardDate(date)));
Expand All @@ -243,7 +243,7 @@ public void testValidDateHeaderIsParsed() {
}

@Test
public void testEpochDateHeaderIsParsed() {
void testEpochDateHeaderIsParsed() {
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
new BasicHeader("Date", DateUtils.formatStandardDate(Instant.EPOCH)));
final Instant dateHeaderValue = entry.getInstant();
Expand All @@ -252,7 +252,7 @@ public void testEpochDateHeaderIsParsed() {
}

@Test
public void testDateParsedOnce() {
void testDateParsedOnce() {
final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
new BasicHeader("Date", DateUtils.formatStandardDate(date)));
Expand All @@ -263,7 +263,7 @@ public void testDateParsedOnce() {
}

@Test
public void testExpiresParsedOnce() {
void testExpiresParsedOnce() {
final Instant date = Instant.now().with(ChronoField.MILLI_OF_SECOND, 0);
entry = makeEntry(Instant.now(), Instant.now(), HttpStatus.SC_OK,
new BasicHeader("Last-Modified", DateUtils.formatStandardDate(date)));
Expand All @@ -278,7 +278,7 @@ private static Instant createInstant(final int year, final Month month, final in
}

@Test
public void testIsCacheEntryNewer() throws Exception {
void testIsCacheEntryNewer() {
assertFalse(HttpCacheEntry.isNewer(null, null));
entry = makeEntry();
final HeaderGroup message = new HeaderGroup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TestHttpCacheEntryFactory {
class TestHttpCacheEntryFactory {

private Instant requestDate;
private Instant responseDate;
Expand All @@ -69,7 +69,7 @@ public class TestHttpCacheEntryFactory {
private HttpCacheEntryFactory impl;

@BeforeEach
public void setUp() throws Exception {
void setUp() {
requestDate = Instant.now().minusSeconds(1);
responseDate = Instant.now();

Expand All @@ -87,7 +87,7 @@ public void setUp() throws Exception {
}

@Test
public void testFilterHopByHopAndConnectionSpecificHeaders() {
void testFilterHopByHopAndConnectionSpecificHeaders() {
response.setHeaders(
new BasicHeader(HttpHeaders.CONNECTION, "blah, blah, this, that"),
new BasicHeader("Blah", "huh?"),
Expand All @@ -106,7 +106,7 @@ public void testFilterHopByHopAndConnectionSpecificHeaders() {
}

@Test
public void testHeadersAreMergedCorrectly() {
void testHeadersAreMergedCorrectly() {
entry = HttpTestUtils.makeCacheEntry(
new BasicHeader("Date", DateUtils.formatStandardDate(responseDate)),
new BasicHeader("ETag", "\"etag\""));
Expand All @@ -118,7 +118,7 @@ public void testHeadersAreMergedCorrectly() {
}

@Test
public void testNewerHeadersReplaceExistingHeaders() {
void testNewerHeadersReplaceExistingHeaders() {
entry = HttpTestUtils.makeCacheEntry(
new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
new BasicHeader("Cache-Control", "private"),
Expand All @@ -139,7 +139,7 @@ public void testNewerHeadersReplaceExistingHeaders() {
}

@Test
public void testNewHeadersAreAddedByMerge() {
void testNewHeadersAreAddedByMerge() {
entry = HttpTestUtils.makeCacheEntry(
new BasicHeader("Date", DateUtils.formatStandardDate(requestDate)),
new BasicHeader("ETag", "\"etag\""));
Expand All @@ -156,7 +156,7 @@ public void testNewHeadersAreAddedByMerge() {
}

@Test
public void entryWithMalformedDateIsStillUpdated() throws Exception {
void entryWithMalformedDateIsStillUpdated() {
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo,
new BasicHeader("ETag", "\"old\""),
new BasicHeader("Date", "bad-date"));
Expand All @@ -169,7 +169,7 @@ public void entryWithMalformedDateIsStillUpdated() throws Exception {
}

@Test
public void entryIsStillUpdatedByResponseWithMalformedDate() throws Exception {
void entryIsStillUpdatedByResponseWithMalformedDate() {
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo,
new BasicHeader("ETag", "\"old\""),
new BasicHeader("Date", DateUtils.formatStandardDate(tenSecondsAgo)));
Expand All @@ -182,14 +182,14 @@ public void entryIsStillUpdatedByResponseWithMalformedDate() throws Exception {
}

@Test
public void testUpdateCacheEntryReturnsDifferentEntryInstance() {
void testUpdateCacheEntryReturnsDifferentEntryInstance() {
entry = HttpTestUtils.makeCacheEntry();
final HttpCacheEntry newEntry = impl.createUpdated(requestDate, responseDate, host, request, response, entry);
Assertions.assertNotSame(newEntry, entry);
}

@Test
public void testCreateRootVariantEntry() {
void testCreateRootVariantEntry() {
request.setHeaders(
new BasicHeader("Keep-Alive", "timeout, max=20"),
new BasicHeader("X-custom", "my stuff"),
Expand Down Expand Up @@ -241,7 +241,7 @@ public void testCreateRootVariantEntry() {
}

@Test
public void testCreateResourceEntry() {
void testCreateResourceEntry() {
request.setHeaders(
new BasicHeader("Keep-Alive", "timeout, max=20"),
new BasicHeader("X-custom", "my stuff"),
Expand Down Expand Up @@ -285,7 +285,7 @@ public void testCreateResourceEntry() {
}

@Test
public void testCreateUpdatedResourceEntry() {
void testCreateUpdatedResourceEntry() {
final Resource resource = HttpTestUtils.makeRandomResource(128);
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(
tenSecondsAgo,
Expand Down Expand Up @@ -347,7 +347,7 @@ public void testCreateUpdatedResourceEntry() {
}

@Test
public void testUpdateNotModifiedIfResponseOlder() {
void testUpdateNotModifiedIfResponseOlder() {
entry = HttpTestUtils.makeCacheEntry(twoSecondsAgo, now,
new BasicHeader("Date", DateUtils.formatStandardDate(oneSecondAgo)),
new BasicHeader("ETag", "\"new-etag\""));
Expand All @@ -360,7 +360,7 @@ public void testUpdateNotModifiedIfResponseOlder() {
}

@Test
public void testUpdateHasLatestRequestAndResponseDates() {
void testUpdateHasLatestRequestAndResponseDates() {
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo);
final HttpCacheEntry updated = impl.createUpdated(twoSecondsAgo, oneSecondAgo, host, request, response, entry);

Expand All @@ -369,7 +369,7 @@ public void testUpdateHasLatestRequestAndResponseDates() {
}

@Test
public void cannotUpdateFromANon304OriginResponse() throws Exception {
void cannotUpdateFromANon304OriginResponse() {
entry = HttpTestUtils.makeCacheEntry();
response = new BasicHttpResponse(HttpStatus.SC_OK, "OK");
Assertions.assertThrows(IllegalArgumentException.class, () ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class CacheControlGeneratorTest {
class CacheControlGeneratorTest {

private final CacheControlHeaderGenerator generator = CacheControlHeaderGenerator.INSTANCE;

@Test
public void testGenerateRequestCacheControlHeader() {
void testGenerateRequestCacheControlHeader() {
assertThat(generator.generate(
RequestCacheControl.builder()
.setMaxAge(12)
Expand Down Expand Up @@ -77,7 +77,7 @@ public void testGenerateRequestCacheControlHeader() {
}

@Test
public void testGenerateRequestCacheControlHeaderNoDirectives() {
void testGenerateRequestCacheControlHeaderNoDirectives() {
final RequestCacheControl cacheControl = RequestCacheControl.builder()
.build();
Assertions.assertNull(generator.generate(cacheControl));
Expand Down
Loading