diff --git a/src/main/java/org/takes/facets/hamcrest/HmRqHeader.java b/src/main/java/org/takes/facets/hamcrest/HmRqHeader.java index c19bf7fda..52201310f 100644 --- a/src/main/java/org/takes/facets/hamcrest/HmRqHeader.java +++ b/src/main/java/org/takes/facets/hamcrest/HmRqHeader.java @@ -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 entry = @@ -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; } diff --git a/src/test/java/org/takes/facets/hamcrest/HmRqHeaderTest.java b/src/test/java/org/takes/facets/hamcrest/HmRqHeaderTest.java index 16bea6f66..93d657247 100644 --- a/src/test/java/org/takes/facets/hamcrest/HmRqHeaderTest.java +++ b/src/test/java/org/takes/facets/hamcrest/HmRqHeaderTest.java @@ -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 @@ -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( @@ -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 @@ -99,11 +99,12 @@ 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")) @@ -111,11 +112,11 @@ public void testsHeaderNameAndValueNotAvailable() throws Exception { } /** - * 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(), @@ -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.iterableWithSize(0))