Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit f264781

Browse files
committed
JERSEY-3189: unit test fix and javadoc adjustment.
Change-Id: Iae2b909f5692ed1791d8ee633543cdc9514b57bd
1 parent 39fcdac commit f264781

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

core-common/src/main/java/org/glassfish/jersey/message/internal/OutboundMessageContext.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ private <T> T singleHeader(String name, Class<T> valueType, Function<String, T>
205205
return convertNull ? converter.apply(null) : null;
206206
}
207207
if (values.size() > 1) {
208-
throw new HeaderValueException(LocalizationMessages.TOO_MANY_HEADER_VALUES(name, values.toString()),
208+
throw new HeaderValueException(
209+
LocalizationMessages.TOO_MANY_HEADER_VALUES(name, values.toString()),
209210
HeaderValueException.Context.OUTBOUND);
210211
}
211212

@@ -356,7 +357,8 @@ public List<Locale> getAcceptableLanguages() {
356357
} else {
357358
conversionApplied = true;
358359
try {
359-
result.addAll(Lists.transform(HttpHeaderReader.readAcceptLanguage(HeaderUtils.asString(value, rd)),
360+
result.addAll(Lists.transform(
361+
HttpHeaderReader.readAcceptLanguage(HeaderUtils.asString(value, rd)),
360362
new Function<AcceptableLanguageTag, Locale>() {
361363

362364
@Override
@@ -428,8 +430,8 @@ public Set<String> getAllowedMethods() {
428430
* should be preferred over this method, since it returns a {@code long}
429431
* instead and is therefore more portable.</P>
430432
*
431-
* @return Content-Length as a postive integer if present and valid number. In other
432-
* cases returns -1.
433+
* @return Content-Length as a postive integer if present and valid number, {@code -1} if negative number.
434+
* @throws ProcessingException when {@link Integer#parseInt(String)} (String)} throws {@link NumberFormatException}.
433435
*/
434436
public int getLength() {
435437
return singleHeader(HttpHeaders.CONTENT_LENGTH, Integer.class, new Function<String, Integer>() {
@@ -454,8 +456,8 @@ public Integer apply(String input) {
454456
/**
455457
* Get Content-Length value.
456458
*
457-
* @return Content-Length as a positive long if present and valid number. In other
458-
* cases returns -1.
459+
* @return Content-Length as a positive long if present and valid number, {@code -1} if negative number.
460+
* @throws ProcessingException when {@link Long#parseLong(String)} throws {@link NumberFormatException}.
459461
*/
460462
public long getLengthLong() {
461463
return singleHeader(HttpHeaders.CONTENT_LENGTH, Long.class, new Function<String, Long>() {
@@ -581,12 +583,13 @@ public Set<Link> getLinks() {
581583

582584
if (conversionApplied) {
583585
// cache converted
584-
headers.put(HttpHeaders.LINK, new ArrayList<Object>(Collections2.transform(result, new Function<Link, Object>() {
585-
@Override
586-
public Object apply(Link input) {
587-
return input;
588-
}
589-
})));
586+
headers.put(HttpHeaders.LINK, new ArrayList<Object>(Collections2
587+
.transform(result, new Function<Link, Object>() {
588+
@Override
589+
public Object apply(Link input) {
590+
return input;
591+
}
592+
})));
590593
}
591594

592595
return Collections.unmodifiableSet(result);

core-common/src/test/java/org/glassfish/jersey/message/internal/OutboundMessageContextTest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.util.List;
4848
import java.util.Locale;
4949

50+
import javax.ws.rs.ProcessingException;
5051
import javax.ws.rs.core.EntityTag;
5152
import javax.ws.rs.core.HttpHeaders;
5253
import javax.ws.rs.core.Link;
@@ -63,6 +64,7 @@
6364
import static org.junit.Assert.assertNull;
6465
import static org.junit.Assert.assertThat;
6566
import static org.junit.Assert.assertTrue;
67+
import static org.junit.Assert.fail;
6668

6769
/**
6870
* {@link OutboundMessageContext} test.
@@ -228,11 +230,19 @@ public void testGetLength() {
228230
@Test
229231
public void testGetLength_tooLongForInt() {
230232
OutboundMessageContext r = new OutboundMessageContext();
231-
long length = Integer.MAX_VALUE + 5;
233+
long length = Integer.MAX_VALUE + 5L;
232234
r.getHeaders().add("Content-Length", length);
233235

234-
// value is not a valid integer -> returning -1 (see the javadoc).
235-
assertEquals(-1, r.getLength());
236+
236237
assertEquals(length, r.getLengthLong());
238+
239+
// value is not a valid integer -> ProcessingException is thrown.
240+
try {
241+
r.getLength();
242+
} catch (ProcessingException e) {
243+
return;
244+
}
245+
246+
fail();
237247
}
238248
}

0 commit comments

Comments
 (0)