Skip to content

Commit

Permalink
yegor256#336 problem reproduced
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegor Bugayenko committed Jun 8, 2015
1 parent bb81698 commit 6eb2337
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/takes/misc/Concat.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public Concat(final Iterable<T> aitb, final Iterable<T> bitb) {
this.right = bitb;
}

@Override
public String toString() {
return String.format("%s, %s", this.left, this.right);
}

@Override
public Iterator<T> iterator() {
return new Concat.ConcatIterator<T>(
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/takes/misc/Select.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public Select(final Iterable<T> itb, final Condition<T> cond) {
this.condition = cond;
}

@Override
public String toString() {
return String.format("%s [if %s]", this.list, this.condition);
}

@Override
public Iterator<T> iterator() {
return new SelectIterator<T>(
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/takes/misc/Transform.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ public Transform(final Iterable<T> itb,
this.action = act;
}

@Override
public final String toString() {
return String.format("%s [via %s]", this.list, this.action);
}

@Override
public final Iterator<K> iterator() {
return new TransformIterator<T, K>(this.list.iterator(), this.action);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/takes/rs/RsWithHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
*/
@EqualsAndHashCode(callSuper = true)
public final class RsWithHeader extends RsWrap {

/**
* Pattern for all other lines in the head.
*/
Expand Down Expand Up @@ -111,18 +112,17 @@ public InputStream body() throws IOException {
return res.body();
}
}
);
);
}

/**
* Add to head additional header.
* @param head Original head
* @param header Value witch will be added to head
* @return Head with additional header
* @throws IOException If fails
*/
private static Iterable<String> extend(final Iterable<String> head,
final String header) throws IOException {
final String header) {
if (!RsWithHeader.HEADER.matcher(header).matches()) {
throw new IllegalArgumentException(
String.format(
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/takes/rs/RsWithStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
*/
@EqualsAndHashCode(callSuper = true)
public final class RsWithStatus extends RsWrap {

/**
* Statuses and their reasons.
*/
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/org/takes/rs/RsWithType.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,19 @@ public final class RsWithType extends RsWrap {
* @param type Content type
*/
public RsWithType(final Response res, final CharSequence type) {
super(
new RsWithHeader(new RsWithoutHeader(res, HEADER), HEADER, type)
super(RsWithType.make(res, type));
}

/**
* Ctor.
* @param res Original response
* @param type Content type
* @return Response
*/
private static Response make(final Response res, final CharSequence type) {
return new RsWithHeader(
new RsWithoutHeader(res, RsWithType.HEADER),
RsWithType.HEADER, type
);
}
}
24 changes: 24 additions & 0 deletions src/test/java/org/takes/rs/RsWithStatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.takes.Response;

/**
* Test case for {@link RsWithStatus}.
Expand Down Expand Up @@ -62,4 +63,27 @@ public void addsStatus() throws IOException {
)
);
}

/**
* RsWithStatus can add status multiple times.
* @throws IOException If some problem inside
*/
@Test
public void addsStatusMultipleTimes() throws IOException {
final Response response = new RsWithStatus(
new RsWithStatus(
new RsEmpty(),
HttpURLConnection.HTTP_NOT_FOUND
),
HttpURLConnection.HTTP_SEE_OTHER
);
MatcherAssert.assertThat(
response.head(),
Matchers.<String>iterableWithSize(3)
);
MatcherAssert.assertThat(
response.head(),
Matchers.<String>iterableWithSize(3)
);
}
}

0 comments on commit 6eb2337

Please sign in to comment.