Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jul 9, 2017
2 parents bfe30c3 + 8042226 commit 4731fcc
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 8 deletions.
79 changes: 79 additions & 0 deletions src/main/java/org/cactoos/InputHasContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Yegor Bugayenko
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.cactoos;

import org.cactoos.io.InputAsBytes;
import org.cactoos.text.BytesAsText;
import org.cactoos.text.UncheckedText;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.core.IsEqual;

/**
* Matcher for the input.
*
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @since 0.11
*/
public final class InputHasContent extends TypeSafeMatcher<Input> {

/**
* Matcher of the value.
*/
private final Matcher<String> matcher;

/**
* Ctor.
* @param text The text to match against
*/
public InputHasContent(final String text) {
this(new IsEqual<>(text));
}

/**
* Ctor.
* @param mtr Matcher of the text
*/
public InputHasContent(final Matcher<String> mtr) {
super();
this.matcher = mtr;
}

@Override
public boolean matchesSafely(final Input item) {
return this.matcher.matches(
new UncheckedText(
new BytesAsText(new InputAsBytes(item))
).asString()
);
}

@Override
public void describeTo(final Description description) {
description.appendText("Input with ");
description.appendDescriptionOf(this.matcher);
}
}
11 changes: 3 additions & 8 deletions src/test/java/org/cactoos/io/FileAsInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.cactoos.TextHasString;
import org.cactoos.text.BytesAsText;
import org.cactoos.InputHasContent;
import org.hamcrest.MatcherAssert;
import org.junit.Test;

Expand All @@ -49,12 +48,8 @@ public void readsSimpleFileContent() throws IOException {
Files.write(temp, content.getBytes(StandardCharsets.UTF_8));
MatcherAssert.assertThat(
"Can't read file content",
new BytesAsText(
new InputAsBytes(
new PathAsInput(temp)
)
),
new TextHasString(content)
new PathAsInput(temp),
new InputHasContent(content)
);
}

Expand Down

0 comments on commit 4731fcc

Please sign in to comment.