Repository: yegor256/cactoos
Pull request #38 (2017-05-26 19:23:34)

Sprintf rename
- rename Sprintf to FormattedText
- add unit test


Patch:
diff --git a/src/main/java/org/cactoos/io/ResourceAsInput.java b/src/main/java/org/cactoos/io/ResourceAsInput.java
index 86d539e9..dd9bb083 100644
--- a/src/main/java/org/cactoos/io/ResourceAsInput.java
+++ b/src/main/java/org/cactoos/io/ResourceAsInput.java
@@ -26,7 +26,7 @@ package org.cactoos.io;
 import java.io.IOException;
 import java.io.InputStream;
 import org.cactoos.Input;
-import org.cactoos.text.Sprintf;
+import org.cactoos.text.FormattedText;
 
 /**
  * Jar class resource.
@@ -76,7 +76,7 @@ public final class ResourceAsInput implements Input {
         final InputStream input = this.loader.getResourceAsStream(this.path);
         if (input == null) {
             throw new IOException(
-                new Sprintf(
+                new FormattedText(
                     "Resource '%s' was not found",
                     this.path
                 ).asString()
diff --git a/src/main/java/org/cactoos/text/Sprintf.java b/src/main/java/org/cactoos/text/FormattedText.java
similarity index 90%
rename from src/main/java/org/cactoos/text/Sprintf.java
rename to src/main/java/org/cactoos/text/FormattedText.java
index d052ea42..58b384a1 100644
--- a/src/main/java/org/cactoos/text/Sprintf.java
+++ b/src/main/java/org/cactoos/text/FormattedText.java
@@ -30,7 +30,7 @@ import java.util.Formatter;
 import org.cactoos.Text;
 
 /**
- * Text in Sprinf.
+ * Text in Sprinf format.
  *
  * <p>There is no thread-safety guarantee.
  *
@@ -38,7 +38,7 @@ import org.cactoos.Text;
  * @version $Id$
  * @since 0.1
  */
-public final class Sprintf implements Text {
+public final class FormattedText implements Text {
 
     /**
      * Pattern.
@@ -55,7 +55,7 @@ public final class Sprintf implements Text {
      * @param ptn Pattern
      * @param arguments Arguments
      */
-    public Sprintf(final String ptn, final Object... arguments) {
+    public FormattedText(final String ptn, final Object... arguments) {
         this(ptn, Arrays.asList(arguments));
     }
 
@@ -64,7 +64,7 @@ public final class Sprintf implements Text {
      * @param ptn Pattern
      * @param arguments Arguments
      */
-    public Sprintf(final String ptn, final Collection<Object> arguments) {
+    public FormattedText(final String ptn, final Collection<Object> arguments) {
         this.pattern = ptn;
         this.args = Collections.unmodifiableCollection(arguments);
     }
@@ -79,5 +79,4 @@ public final class Sprintf implements Text {
         }
         return out.toString();
     }
-
 }


Test patch:
diff --git a/src/test/java/org/cactoos/text/FormattedTextTest.java b/src/test/java/org/cactoos/text/FormattedTextTest.java
new file mode 100644
index 00000000..2a4c273d
--- /dev/null
+++ b/src/test/java/org/cactoos/text/FormattedTextTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.text;
+
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+/**
+ * Test case for {@link FormattedText}.
+ *
+ * @author Andriy Kryvtsun (kontiky@gmail.com)
+ * @version $Id$
+ * @since 0.1
+ */
+public final class FormattedTextTest {
+
+    /**
+     * FormattedText produces correct text.
+     */
+    @Test
+    public void formatsText() {
+        MatcherAssert.assertThat(
+            new FormattedText(
+                "%d. Formatted %s", 1, "text"
+            ).asString(),
+            Matchers.equalTo("1. Formatted text")
+        );
+    }
+}