Skip to content

Commit

Permalink
#413: Some improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
bdragan committed Nov 16, 2015
1 parent 49af8fa commit 1a5baff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/takes/facets/hamcrest/HmRqHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ public EntryHeaderMatcher(
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public boolean matches(final RqHeaders headers) throws IOException {
boolean result = false;
outer:
for (final String name : headers.names()) {
for (final String value: headers.header(name)) {
final Map.Entry<String, String> entry =
Expand All @@ -163,9 +162,12 @@ public boolean matches(final RqHeaders headers) throws IOException {
);
if (this.matcher.matches(entry)) {
result = true;
break outer;
break;
}
}
if (result) {
break;
}
}
return result;
}
Expand Down
21 changes: 11 additions & 10 deletions src/test/java/org/takes/facets/hamcrest/HmRqHeaderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public final class HmRqHeaderTest {

/**
* HmRqHeader can test header available.
* HmRqHeader can test whether a header is available.
* @throws Exception If some problem inside
*/
@Test
Expand All @@ -64,11 +64,11 @@ public void testsHeaderAvailable() throws Exception {
}

/**
* HmRqHeader can test header not available.
* HmRqHeader can test whether a header value is not available.
* @throws Exception If some problem inside
*/
@Test
public void testsHeaderNotAvailable() throws Exception {
public void testsHeaderValueNotAvailable() throws Exception {
MatcherAssert.assertThat(
new RqFake(
Arrays.asList(
Expand All @@ -87,7 +87,7 @@ public void testsHeaderNotAvailable() throws Exception {
}

/**
* HmRqHeader can test header name and value available.
* HmRqHeader can test whether header name and value are available.
* @throws Exception If some problem inside
*/
@Test
Expand All @@ -99,23 +99,24 @@ public void testsHeaderNameAndValueAvailable() throws Exception {
}

/**
* HmRqHeader can test header name and value not available.
* HmRqHeader can test whether header name is available
* and value is not available.
* @throws Exception If some problem inside
*/
@Test
public void testsHeaderNameAndValueNotAvailable() throws Exception {
public void testsValueNotAvailable() throws Exception {
MatcherAssert.assertThat(
new RqWithHeader(new RqFake(), "header2: value2"),
Matchers.not(new HmRqHeader("header2", "value21"))
);
}

/**
* HmRqHeader can test headers available.
* HmRqHeader can test whether multiple headers are available.
* @throws Exception If some problem inside
*/
@Test
public void testsHeadersAvailable() throws Exception {
public void testsMultipleHeadersAvailable() throws Exception {
MatcherAssert.assertThat(
new RqWithHeaders(
new RqFake(),
Expand All @@ -126,11 +127,11 @@ public void testsHeadersAvailable() throws Exception {
}

/**
* HmRqHeader can test headers not available.
* HmRqHeader can test whether a header is not available.
* @throws Exception If some problem inside
*/
@Test
public void testsHeadersNotAvailable() throws Exception {
public void testsHeaderNotAvailable() throws Exception {
MatcherAssert.assertThat(
new RqWithHeaders(new RqFake(), "header4: value4"),
new HmRqHeader("header41", Matchers.<String>iterableWithSize(0))
Expand Down

0 comments on commit 1a5baff

Please sign in to comment.