Skip to content
Permalink
Browse files

replaced string concatenation by formatting

  • Loading branch information...
maciejmikosik committed Feb 22, 2018
1 parent af7e1b3 commit d220b4b8fc57bbfd8220e237df92dc1b4a82a01d
Showing with 395 additions and 252 deletions.
  1. +3 −2 main/java/org/testory/common/Effect.java
  2. +1 −1 main/java/org/testory/common/ObjectFormatter.java
  3. +13 −9 main/java/org/testory/plumbing/facade/ConfigurableFacade.java
  4. +2 −1 main/java/org/testory/plumbing/mock/Mocked.java
  5. +2 −1 main/java/org/testory/plumbing/mock/NiceMockMaker.java
  6. +2 −1 main/java/org/testory/plumbing/mock/Stubbed.java
  7. +2 −1 main/java/org/testory/plumbing/mock/UniqueNamer.java
  8. +2 −1 main/java/org/testory/proxy/Invocation.java
  9. +2 −1 main/java/org/testory/proxy/Typing.java
  10. +4 −3 test/java/org/testory/TestAnyA.java
  11. +4 −3 test/java/org/testory/TestAnyClass.java
  12. +2 −1 test/java/org/testory/TestAnyInstanceOf.java
  13. +3 −2 test/java/org/testory/TestAnyThe.java
  14. +5 −4 test/java/org/testory/TestInvocationMatchers.java
  15. +5 −4 test/java/org/testory/TestMatchingInvocations.java
  16. +2 −1 test/java/org/testory/TestThenCalled.java
  17. +10 −9 test/java/org/testory/TestThenCalledAllOverloadings.java
  18. +7 −4 test/java/org/testory/TestThenCalledInOrder.java
  19. +3 −2 test/java/org/testory/TestThenCalledNever.java
  20. +3 −3 test/java/org/testory/TestThenCalledTimesInteger.java
  21. +4 −3 test/java/org/testory/TestThenCalledTimesMatcher.java
  22. +23 −15 test/java/org/testory/TestThenEqual.java
  23. +20 −12 test/java/org/testory/TestThenObjectMatcher.java
  24. +6 −3 test/java/org/testory/TestThenReturned.java
  25. +38 −24 test/java/org/testory/TestThenReturnedMatcher.java
  26. +36 −24 test/java/org/testory/TestThenReturnedObject.java
  27. +8 −5 test/java/org/testory/TestThenThrown.java
  28. +38 −24 test/java/org/testory/TestThenThrownClass.java
  29. +41 −26 test/java/org/testory/TestThenThrownMatcher.java
  30. +27 −17 test/java/org/testory/TestThenThrownThrowable.java
  31. +6 −4 test/java/org/testory/TestWhen.java
  32. +11 −6 test/java/org/testory/TestWhenChained.java
  33. +12 −7 test/java/org/testory/TestWhenClosure.java
  34. +7 −4 test/java/org/testory/TestWhenVoidClosure.java
  35. +2 −1 test/java/org/testory/common/TestClassesCanAssign.java
  36. +2 −1 test/java/org/testory/common/TestClassesCanInvoke.java
  37. +2 −1 test/java/org/testory/common/TestClassesCanReturn.java
  38. +2 −1 test/java/org/testory/common/TestDelegatingMatcher.java
  39. +4 −3 test/java/org/testory/common/TestEffect.java
  40. +5 −2 test/java/org/testory/common/TestMatchersArrayOf.java
  41. +2 −1 test/java/org/testory/common/TestMatchersEqualDeep.java
  42. +5 −2 test/java/org/testory/common/TestMatchersListOf.java
  43. +2 −1 test/java/org/testory/common/TestMatchersSame.java
  44. +6 −5 test/java/org/testory/common/TestObjectFormatter.java
  45. +1 −1 test/java/org/testory/common/TestSequenceFormatter.java
  46. +3 −1 test/java/org/testory/proxy/TestInvocation.java
  47. +2 −1 test/java/org/testory/proxy/proxer/Tester.java
  48. +3 −3 test/java/org/testory/testing/HamcrestMatchers.java
@@ -1,5 +1,6 @@
package org.testory.common;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

public abstract class Effect {
@@ -18,7 +19,7 @@ private ReturnedObject(Object object) {
}

public String toString() {
return "returned(" + object + ")";
return format("returned(%s)", object);
}
}

@@ -38,7 +39,7 @@ private Thrown(Throwable throwable) {
}

public String toString() {
return "thrown(" + throwable + ")";
return format("thrown(%s)", throwable);
}
}

@@ -23,7 +23,7 @@ public String format(@Nullable Object object) {
}

private String formatArray(Object array) {
return "[" + sequence(", ", this).format(arrayAsIterable(array)) + "]";
return String.format("[%s]", sequence(", ", this).format(arrayAsIterable(array)));
}

private Iterable<Object> arrayAsIterable(final Object array) {
@@ -1,5 +1,7 @@
package org.testory.plumbing.facade;

import static java.lang.String.format;
import static java.util.Arrays.asList;
import static java.util.Objects.deepEquals;
import static org.testory.TestoryAssertionError.assertionError;
import static org.testory.common.Classes.defaultValue;
@@ -10,6 +12,8 @@
import static org.testory.common.Matchers.asMatcher;
import static org.testory.common.Matchers.isDiagnosticMatcher;
import static org.testory.common.Matchers.isMatcher;
import static org.testory.common.ObjectFormatter.objectFormatter;
import static org.testory.common.SequenceFormatter.sequence;
import static org.testory.common.Throwables.gently;
import static org.testory.common.Throwables.printStackTrace;
import static org.testory.plumbing.Inspecting.inspecting;
@@ -22,6 +26,9 @@
import static org.testory.proxy.handler.ReturningHandler.returning;
import static org.testory.proxy.handler.ThrowingHandler.throwing;

import java.util.ArrayList;
import java.util.List;

import org.testory.common.Closure;
import org.testory.common.Effect;
import org.testory.common.Effect.ReturnedObject;
@@ -229,7 +236,7 @@ public boolean matches(Invocation invocation) {
}

public String toString() {
return "onInstance(" + mock + ")";
return format("onInstance(%s)", mock);
}
};
}
@@ -241,7 +248,7 @@ public boolean matches(Invocation invocation) {
}

public String toString() {
return "onReturn(" + type.getName() + ")";
return format("onReturn(%s)", type.getName());
}
};
}
@@ -254,13 +261,10 @@ public boolean matches(Invocation invocation) {
}

public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("onRequest(").append(type.getName());
for (Object argument : arguments) {
builder.append(", ").append(argument);
}
builder.append(")");
return builder.toString();
List<Object> elements = new ArrayList<>();
elements.add(type.getName());
elements.addAll(asList(arguments));
return format("onRequest(%s)", sequence(", ", objectFormatter()).format(elements));
}
};
}
@@ -1,5 +1,6 @@
package org.testory.plumbing.mock;

import static java.lang.String.format;
import static org.testory.plumbing.PlumbingException.check;

public class Mocked {
@@ -18,6 +19,6 @@ public static Mocked mocked(Object mock, String name) {
}

public String toString() {
return "mocked(" + mock + ", " + name + ")";
return format("mocked(%s, %s)", mock, name);
}
}
@@ -1,5 +1,6 @@
package org.testory.plumbing.mock;

import static java.lang.String.format;
import static org.testory.common.Classes.defaultValue;
import static org.testory.plumbing.PlumbingException.check;
import static org.testory.plumbing.mock.Stubbed.stubbed;
@@ -48,7 +49,7 @@ public boolean matches(Invocation invocation) {
}

public String toString() {
return "onInstance(" + mock + ")";
return format("onInstance(%s)", mock);
}
};
}
@@ -1,5 +1,6 @@
package org.testory.plumbing.mock;

import static java.lang.String.format;
import static org.testory.plumbing.PlumbingException.check;

import org.testory.proxy.Handler;
@@ -21,6 +22,6 @@ public static Stubbed stubbed(InvocationMatcher invocationMatcher, Handler handl
}

public String toString() {
return "stubbed(" + invocationMatcher + ", " + handler + ")";
return format("stubbed(%s, %s)", invocationMatcher, handler);
}
}
@@ -1,5 +1,6 @@
package org.testory.plumbing.mock;

import static java.lang.String.format;
import static org.testory.plumbing.PlumbingException.check;
import static org.testory.plumbing.history.FilteredHistory.filter;

@@ -25,7 +26,7 @@ public String name(Class<?> type) {
check(type != null);
List<String> usedNames = usedNames();
for (int i = 0;; i++) {
String name = "mock" + type.getSimpleName() + i;
String name = format("mock%s%s", type.getSimpleName(), i);
if (!usedNames.contains(name)) {
return name;
}
@@ -1,5 +1,6 @@
package org.testory.proxy;

import static java.lang.String.format;
import static java.util.Objects.deepEquals;
import static org.testory.common.Classes.canInvoke;
import static org.testory.common.Classes.setAccessible;
@@ -64,6 +65,6 @@ public int hashCode() {
}

public String toString() {
return "invocation(" + method + ", " + instance + ", " + arguments + ")";
return format("invocation(%s, %s, %s)", method, instance, arguments);
}
}
@@ -1,5 +1,6 @@
package org.testory.proxy;

import static java.lang.String.format;
import static java.util.Arrays.asList;
import static org.testory.common.Collections.immutable;
import static org.testory.proxy.ProxyException.check;
@@ -84,6 +85,6 @@ public int hashCode() {
}

public String toString() {
return "typing(" + superclass + ", " + interfaces + ")";
return format("typing(%s, %s)", superclass, interfaces);
}
}
@@ -1,5 +1,6 @@
package org.testory;

import static java.lang.String.format;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -112,19 +113,19 @@ public void prints_value() {
thenCalled(mock).invoke(a(intA));
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(".invoke(a(" + intA + "))"));
assertThat(e, hasMessageContaining(format(".invoke(a(%s))", intA)));
}
try {
thenCalled(mock).invoke(a(object));
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(".invoke(a(" + object + "))"));
assertThat(e, hasMessageContaining(format(".invoke(a(%s))", object)));
}
try {
thenCalled(mock).invoke(a(new Object[] { object }));
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(".invoke(a([" + object + "]))"));
assertThat(e, hasMessageContaining(format(".invoke(a([%s]))", object)));
}
}

@@ -1,5 +1,6 @@
package org.testory;

import static java.lang.String.format;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertNotSame;
@@ -105,7 +106,7 @@ public void printing_includes_matcher() {
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(
mock + ".returnObject(any(" + Object.class.getName() + ", " + matcher + "))"));
format("%s.returnObject(any(%s, %s))", mock, Object.class.getName(), matcher)));
}
}

@@ -116,7 +117,7 @@ public void printing_skips_implicit_matcher() {
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(
mock + ".returnObject(any(" + Object.class.getName() + "))"));
format("%s.returnObject(any(%s))", mock, Object.class.getName())));
}
}

@@ -127,7 +128,7 @@ public void printing_handles_varargs() {
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(
mock + ".varargs(" + object + ", [any(" + Object.class.getName() + ")])"));
format("%s.varargs(%s, [any(%s)])", mock, object, Object.class.getName())));
}
}

@@ -1,5 +1,6 @@
package org.testory;

import static java.lang.String.format;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertFalse;
@@ -94,7 +95,7 @@ public void is_printable() {
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(
mock + ".invoke(anyInstanceOf(" + Object.class.getName() + "))"));
format("%s.invoke(anyInstanceOf(%s))", mock, Object.class.getName())));
}
}

@@ -1,5 +1,6 @@
package org.testory;

import static java.lang.String.format;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -94,13 +95,13 @@ public void prints_value() {
thenCalled(mock).invoke(the(object));
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(".invoke(the(" + object + "))"));
assertThat(e, hasMessageContaining(format(".invoke(the(%s))", object)));
}
try {
thenCalled(mock).invoke(the(new Object[] { object }));
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(".invoke(the([" + object + "]))"));
assertThat(e, hasMessageContaining(format(".invoke(the([%s]))", object)));
}
}

@@ -1,5 +1,6 @@
package org.testory;

import static java.lang.String.format;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -74,11 +75,11 @@ public void on_request_matches_invocation_of_method_returning_same_type_and_equa

@Test
public void invocation_matchers_are_printable() {
assertEquals("onInstance(" + mock + ")", onInstance(mock).toString());
assertEquals("onReturn(" + type.getName() + ")", onReturn(type).toString());
assertEquals("onRequest(" + type.getName() + ", " + argument + ")",
assertEquals(format("onInstance(%s)", mock), onInstance(mock).toString());
assertEquals(format("onReturn(%s)", type.getName()), onReturn(type).toString());
assertEquals(format("onRequest(%s, %s)", type.getName(), argument),
onRequest(type, argument).toString());
assertEquals("onRequest(" + type.getName() + ")", onRequest(type).toString());
assertEquals(format("onRequest(%s)", type.getName()), onRequest(type).toString());
}

@Test
@@ -1,5 +1,6 @@
package org.testory;

import static java.lang.String.format;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
@@ -182,28 +183,28 @@ public void matched_invocation_is_printable() {
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(
mock + ".invoke()"));
format("%s.invoke()", mock)));
}
try {
thenCalled(mock).returnObject(object);
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(
mock + ".returnObject(" + object + ")"));
format("%s.returnObject(%s)", mock, object)));
}
try {
thenCalled(mock).acceptObjects(object, otherObject);
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(
mock + ".acceptObjects(" + object + ", " + otherObject + ")"));
format("%s.acceptObjects(%s, %s)", mock, object, otherObject)));
}
try {
thenCalled(mock).varargs(object, otherObject);
fail();
} catch (TestoryAssertionError e) {
assertThat(e, hasMessageContaining(
mock + ".varargs(" + object + ", [" + otherObject + "])"));
format("%s.varargs(%s, [%s])", mock, object, otherObject)));
}
}

@@ -1,5 +1,6 @@
package org.testory;

import static java.lang.String.format;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.testory.Testory.mock;
@@ -117,7 +118,7 @@ public boolean matches(Invocation invocation) {
}

public String toString() {
return "onInstance(" + mock + ")";
return format("onInstance(%s)", mock);
}
};
}

0 comments on commit d220b4b

Please sign in to comment.
You can’t perform that action at this time.