Skip to content

Commit 03cfd94

Browse files
committed
More cleanup and StringBuilder improvements
1 parent 9ca515f commit 03cfd94

2 files changed

Lines changed: 38 additions & 39 deletions

File tree

core/src/main/java/software/xdev/mockserver/formatting/StringFormatter.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ public static StringBuilder[] indentAndToString(final Object... objects)
3939
return indentAndToString(1, objects);
4040
}
4141

42+
@SuppressWarnings("checkstyle:MagicNumber")
4243
public static StringBuilder[] indentAndToString(final int indent, final Object... objects)
4344
{
4445
final StringBuilder[] indentedObjects = new StringBuilder[objects.length];
4546
for(int i = 0; i < objects.length; i++)
4647
{
47-
indentedObjects[i] =
48-
new StringBuilder(NEW_LINE)
49-
.append(NEW_LINE)
50-
.append(PATTERN_MULTI_LINE_START
51-
.matcher(String.valueOf(objects[i]))
52-
.replaceAll(INDENTS.get(indent)))
53-
.append(NEW_LINE);
48+
indentedObjects[i] = new StringBuilder(64) // Default value of 16 is definitely to small here
49+
.append(NEW_LINE)
50+
.append(NEW_LINE)
51+
.append(PATTERN_MULTI_LINE_START
52+
.matcher(String.valueOf(objects[i]))
53+
.replaceAll(INDENTS.get(indent)))
54+
.append(NEW_LINE);
5455
}
5556
return indentedObjects;
5657
}

server/src/main/java/software/xdev/mockserver/matchers/HttpRequestPropertiesMatcher.java

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -212,46 +212,44 @@ private void withProtocol(final Protocol protocol)
212212
@Override
213213
public boolean matches(final MatchDifference context, final RequestDefinition requestDefinition)
214214
{
215-
if(requestDefinition instanceof final HttpRequest request)
215+
if(!(requestDefinition instanceof final HttpRequest request))
216216
{
217-
final StringBuilder becauseBuilder = new StringBuilder();
218-
final boolean overallMatch = this.matches(context, request, becauseBuilder);
219-
if(!this.controlPlaneMatcher)
217+
return requestDefinition == null;
218+
}
219+
220+
final StringBuilder becauseBuilder = new StringBuilder();
221+
final boolean overallMatch = this.matches(context, request, becauseBuilder);
222+
if(!this.controlPlaneMatcher)
223+
{
224+
if(overallMatch)
220225
{
221-
if(overallMatch)
226+
if(LOG.isInfoEnabled())
222227
{
223-
if(LOG.isInfoEnabled())
224-
{
225-
LOG.info(
226-
this.expectation == null ? REQUEST_DID_MATCH : EXPECTATION_DID_MATCH,
227-
request,
228-
this.expectation == null ? this : this.expectation.clone());
229-
}
228+
LOG.info(
229+
this.expectation == null ? REQUEST_DID_MATCH : EXPECTATION_DID_MATCH,
230+
request,
231+
this.expectation == null ? this : this.expectation.clone());
230232
}
231-
else
233+
}
234+
else
235+
{
236+
becauseBuilder.replace(0, 1, "");
237+
final String because = becauseBuilder.toString();
238+
if(LOG.isInfoEnabled())
232239
{
233-
becauseBuilder.replace(0, 1, "");
234-
final String because = becauseBuilder.toString();
235-
if(LOG.isInfoEnabled())
236-
{
237-
LOG.info(
238-
this.expectation == null
239-
? this.didNotMatchRequestBecause
240-
: !becauseBuilder.isEmpty()
241-
? this.didNotMatchExpectationBecause
242-
: this.didNotMatchExpectationWithoutBecause,
243-
request,
244-
this.expectation == null ? this : this.expectation.clone(),
245-
because);
246-
}
240+
LOG.info(
241+
this.expectation == null
242+
? this.didNotMatchRequestBecause
243+
: !becauseBuilder.isEmpty()
244+
? this.didNotMatchExpectationBecause
245+
: this.didNotMatchExpectationWithoutBecause,
246+
request,
247+
this.expectation == null ? this : this.expectation.clone(),
248+
because);
247249
}
248250
}
249-
return overallMatch;
250-
}
251-
else
252-
{
253-
return requestDefinition == null;
254251
}
252+
return overallMatch;
255253
}
256254

257255
@SuppressWarnings({

0 commit comments

Comments
 (0)