Skip to content

Commit

Permalink
Code cleanups with OpenRewrite (frankframework#6909)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkosternl authored May 30, 2024
1 parent a4abeca commit 7e294ea
Show file tree
Hide file tree
Showing 54 changed files with 236 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static CisConversionResult createPasswordFailureResult(String filename, C
if (filename != null) {
msg.append(filename);
}
msg.append(" " + PASSWORD_MESSAGE);
msg.append(" ").append(PASSWORD_MESSAGE);
return createFailureResult(conversionOption, mediaTypeReceived, filename, msg.toString(), null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ public PolicyService getPolicyService() {
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()));
builder.append(" close ["+CMIS_BRIDGE_CLOSE_CONNECTION+"]");
builder.append(getClass().getSimpleName() + "@").append(Integer.toHexString(hashCode()));
builder.append(" close [").append(CMIS_BRIDGE_CLOSE_CONNECTION).append("]");
if(clientBinding != null) {
builder.append(" session ["+clientBinding.getSessionId()+"]");
builder.append(" session [").append(clientBinding.getSessionId()).append("]");
}
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void assertResponse(String string, InputStream response) throws IOExcept
}
private void assertResponse(String string, String result) throws IOException {
String expected = TestFileUtils.getTestFile(string);
assertNotNull("cannot find test file", expected);
assertNotNull(expected, "cannot find test file");

TestAssertions.assertEqualsIgnoreCRLF(expected, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testMtomRequest(String testFileName) throws Throwable {
String result = StreamUtil.streamToString(wrapper.getInputStream());

String boundary = getBoundary(contentType);
assertNotNull("no boundary found", boundary);
assertNotNull(boundary, "no boundary found");
result = result.replace(boundary, "IGNORE"); //Replace the multipart boundary with IGNORE

TestAssertions.assertEqualsIgnoreCRLF(getOutputFile(testFileName), result);
Expand Down
8 changes: 4 additions & 4 deletions commons/src/main/java/org/frankframework/util/ClassUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static Constructor<?> getConstructorOnType(Class<?> clas, Class<?>[] para
} catch (NoSuchMethodException e) {
StringBuilder builder = new StringBuilder("cannot create constructor for Class [" + clas.getName() + "]");
for (int i = 0; i < parameterTypes.length; i++) {
builder.append(", parameter ["+i+"] type [" + parameterTypes[i].getName()+"]");
builder.append(", parameter [").append(i).append("] type [").append(parameterTypes[i].getName()).append("]");
}
log.error(builder.toString(), e);
throw e;
Expand Down Expand Up @@ -377,11 +377,11 @@ private static void appendFieldsAndMethods(StringBuilder result, Object o, Strin
} catch (Exception e) {
value="Could not get value: "+ClassUtils.nameOf(e)+": "+e.getMessage();
}
result.append(" field["+i+"] "+f.getName()+"("+f.getType().getName()+"): ["+value+"]\n");
result.append(" field[").append(i).append("] ").append(f.getName()).append("(").append(f.getType().getName()).append("): [").append(value).append("]\n");
}
for (int i=0; i<methods.length; i++) {
Method m=methods[i];
result.append(" method["+i+"] "+m.getName());
result.append(" method[").append(i).append("] ").append(m.getName());
result.append("\n");
}
result.append("}");
Expand All @@ -404,7 +404,7 @@ public static String debugObject(Object o) {
appendFieldsAndMethods(result,o,"Class",c);
c=c.getSuperclass();
}
result.append("toString=["+o.toString()+"]\n");
result.append("toString=[").append(o.toString()).append("]\n");
return result.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.lang.reflect.Method;

Expand All @@ -24,9 +26,9 @@ public void testConvertToType() {
() -> assertEquals(7L, ClassUtils.convertToType(long.class, "7")),
() -> assertEquals(7L, ClassUtils.convertToType(Long.class, "7")),
() -> assertEquals("7", ClassUtils.convertToType(String.class, "7")),
() -> assertEquals(true, ClassUtils.convertToType(boolean.class, "true")),
() -> assertEquals(true, ClassUtils.convertToType(Boolean.class, "true")),
() -> assertEquals(false, ClassUtils.convertToType(Boolean.class, "niet true")),
() -> assertTrue(ClassUtils.convertToType(boolean.class, "true")),
() -> assertTrue(ClassUtils.convertToType(Boolean.class, "true")),
() -> assertFalse(ClassUtils.convertToType(Boolean.class, "niet true")),
() -> assertEquals(TestEnum.ONE, ClassUtils.convertToType(TestEnum.class, "one")),

() -> assertThrows(IllegalArgumentException.class, ()->ClassUtils.convertToType(Object.class, "dummy")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void setAndGetStringProperty() {
@Test
public void setAndGetBooleanProperty() {
constants.setProperty("property.type.boolean", "true");
assertEquals(true, constants.getBoolean("property.type.boolean", false));
assertTrue(constants.getBoolean("property.type.boolean", false));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void testCreateSimpleUUID() {
@Test
public void testCreateRandomUUIDRemoveDashes() {
String uuid = UUIDUtil.createRandomUUID(true);
assertNotEquals(uuid.substring(8, 9), "-"); // assert that dashes are removed
assertNotEquals("-", uuid.substring(8, 9)); // assert that dashes are removed
assertEquals(32, uuid.length());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public void testConversions() throws Exception {
InputStream boolNull = new ByteArrayInputStream("".getBytes());

assertEquals("string", RequestUtils.convert(String.class, string));
assertEquals(true, RequestUtils.convert(boolean.class, boolTrue));
assertEquals(false, RequestUtils.convert(Boolean.class, boolFalse));
assertEquals(false, RequestUtils.convert(boolean.class, boolNull));
assertTrue(RequestUtils.convert(boolean.class, boolTrue));
assertFalse(RequestUtils.convert(Boolean.class, boolFalse));
assertFalse(RequestUtils.convert(boolean.class, boolNull));
assertEquals(50, RequestUtils.convert(Integer.class, number).intValue());
assertEquals(string, RequestUtils.convert(InputStream.class, string));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ private ConfigurationMessageEvent(ApplicationContext source, String message, Mes
StringBuilder m = new StringBuilder();

String configurationName = getSource().getName();
m.append("Configuration [" + configurationName + "] ");
m.append("Configuration [").append(configurationName).append("] ");

String version = getSource().getVersion();
if (version != null) {
m.append("[" + version + "] ");
m.append("[").append(version).append("] ");
}

m.append(message);
Expand All @@ -77,7 +77,7 @@ private ConfigurationMessageEvent(ApplicationContext source, String message, Mes
}

if (e != null) {
m.append(": " + e.getMessage());
m.append(": ").append(e.getMessage());
}

Date date = new Date(getTimestamp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ public IJob getSchedule(String name) {
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getSimpleName() + "@" + Integer.toHexString(hashCode()));
builder.append(" state ["+getState()+"]");
builder.append(" schedules ["+schedules.size()+"]");
builder.append(getClass().getSimpleName() + "@").append(Integer.toHexString(hashCode()));
builder.append(" state [").append(getState()).append("]");
builder.append(" schedules [").append(schedules.size()).append("]");
if(applicationContext != null) {
builder.append(" applicationContext ["+applicationContext.getDisplayName()+"]");
builder.append(" applicationContext [").append(applicationContext.getDisplayName()).append("]");
}
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public void setDatasourceName(String datasourceName) {
@Override
public String toString() {
StringBuilder builder = new StringBuilder(super.toString());
if(datasourceName != null) builder.append(" datasourceName ["+datasourceName+"]");
if(configuration != null && getFileName() != null) builder.append(" fileName ["+getFileName()+"]");
if(datasourceName != null) builder.append(" datasourceName [").append(datasourceName).append("]");
if(configuration != null && getFileName() != null) builder.append(" fileName [").append(getFileName()).append("]");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public URL getLocalResource(String name) {
@Override
public String toString() {
StringBuilder builder = new StringBuilder(super.toString());
if(getDirectory() != null) builder.append(" directory ["+getDirectory()+"]");
if(getDirectory() != null) builder.append(" directory [").append(getDirectory()).append("]");
return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ public Header authenticate(Credentials credentials, HttpRequest request, final H

@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(getSchemeName()+" [complete=").append(isComplete()).append("]");
return builder.toString();
return getSchemeName() + " [complete=" + isComplete() + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public ApplicationMessageEvent(ApplicationContext source, String message, Messag
StringBuilder m = new StringBuilder();

String applicationName = source.getId();
m.append("Application [" + applicationName + "] ");
m.append("Application [").append(applicationName).append("] ");

String version = ConfigurationUtils.getApplicationVersion();
if (version != null) {
m.append("[" + version + "] ");
m.append("[").append(version).append("] ");
}

m.append(message);
Expand All @@ -73,7 +73,7 @@ public ApplicationMessageEvent(ApplicationContext source, String message, Messag
}

if (e != null) {
m.append(": (" + ClassUtils.nameOf(e) +") "+ e.getMessage());
m.append(": (").append(ClassUtils.nameOf(e)).append(") ").append(e.getMessage());
}

Date date = new Date(getTimestamp());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@ private String[] getEndpoints(List<String> list) {

private void logServletInfo(Dynamic serv, ServletConfiguration config) {
StringBuilder builder = new StringBuilder("registered");
builder.append(" servlet ["+serv.getName()+"]");
builder.append(" servlet [").append(serv.getName()).append("]");
builder.append(" configuration ");
builder.append(config);

getServletContext().log(builder.toString());

if(log.isDebugEnabled()) builder.append(" class ["+serv.getClassName()+"]");
if(log.isDebugEnabled()) builder.append(" class [").append(serv.getClassName()).append("]");
log.info(builder::toString);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void updateLogConfiguration(Level loglevel, Boolean logIntermediaryResul
LoggerContext logContext = LoggerContext.getContext(false);
org.apache.logging.log4j.core.Logger rootLogger = logContext.getRootLogger();
if(rootLogger.getLevel() != loglevel) {
msg.append("LogLevel changed from [" + rootLogger.getLevel() + "] to [" + loglevel +"]");
msg.append("LogLevel changed from [").append(rootLogger.getLevel()).append("] to [").append(loglevel).append("]");
Configurator.setLevel(rootLogger.getName(), loglevel);
}
}
Expand All @@ -94,17 +94,17 @@ private void updateLogConfiguration(Level loglevel, Boolean logIntermediaryResul
if(logIntermediaryResults != null && logIntermediary != logIntermediaryResults) {
AppConstants.getInstance().put(LOG_INTERMEDIARY_RESULTS_PROPERTY, "" + logIntermediaryResults);

if(msg.length() > 0)
msg.append(", logIntermediaryResults from [" + logIntermediary+ "] to [" + logIntermediaryResults + "]");
if(!msg.isEmpty())
msg.append(", logIntermediaryResults from [").append(logIntermediary).append("] to [").append(logIntermediaryResults).append("]");
else
msg.append("logIntermediaryResults changed from [" + logIntermediary+ "] to [" + logIntermediaryResults + "]");
msg.append("logIntermediaryResults changed from [").append(logIntermediary).append("] to [").append(logIntermediaryResults).append("]");
}

if (maxMessageLength != null && maxMessageLength != IbisMaskingLayout.getMaxLength()) {
if(msg.length() > 0)
msg.append(", logMaxMessageLength from [" + IbisMaskingLayout.getMaxLength() + "] to [" + maxMessageLength + "]");
if(!msg.isEmpty())
msg.append(", logMaxMessageLength from [").append(IbisMaskingLayout.getMaxLength()).append("] to [").append(maxMessageLength).append("]");
else
msg.append("logMaxMessageLength changed from [" + IbisMaskingLayout.getMaxLength() + "] to [" + maxMessageLength + "]");
msg.append("logMaxMessageLength changed from [").append(IbisMaskingLayout.getMaxLength()).append("] to [").append(maxMessageLength).append("]");
IbisMaskingLayout.setMaxLength(maxMessageLength);
}

Expand All @@ -116,10 +116,10 @@ private void updateLogConfiguration(Level loglevel, Boolean logIntermediaryResul
ApplicationEventPublisher applicationEventPublisher = getIbisManager().getApplicationEventPublisher();
if (applicationEventPublisher!=null) {
log.info("setting debugger enabled ["+enableDebugger+"]");
if(msg.length() > 0)
msg.append(", enableDebugger from [" + testtoolEnabled + "] to [" + enableDebugger + "]");
if(!msg.isEmpty())
msg.append(", enableDebugger from [").append(testtoolEnabled).append("] to [").append(enableDebugger).append("]");
else
msg.append("enableDebugger changed from [" + testtoolEnabled + "] to [" + enableDebugger + "]");
msg.append("enableDebugger changed from [").append(testtoolEnabled).append("] to [").append(enableDebugger).append("]");
applicationEventPublisher.publishEvent(event);
} else {
log.warn("no applicationEventPublisher, cannot set debugger enabled to ["+enableDebugger+"]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Parameter(String name, String value) {
@Override
public String toString() {
StringBuilder builder = new StringBuilder(super.toString());
if(type != null) builder.append(" type ["+type+"]");
if(type != null) builder.append(" type [").append(type).append("]");
return builder.toString();
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/frankframework/pipes/StreamPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public PipeRunResult doPipe(Message message, PipeLineSession session) throws Pip
} else {
String sessionKeyName = "part_string" + (++stringCounter > 1 ? stringCounter : "");
addSessionKey(session, sessionKeyName, fieldValue);
partsString.append("<part type=\"string\" name=\"" + fieldName + "\" sessionKey=\"" + sessionKeyName + "\" size=\"" + fieldValue.length() + "\"/>");
partsString.append("<part type=\"string\" name=\"").append(fieldName).append("\" sessionKey=\"").append(sessionKeyName).append("\" size=\"").append(fieldValue.length()).append("\"/>");
}
}
} else {
Expand All @@ -204,7 +204,7 @@ public PipeRunResult doPipe(Message message, PipeLineSession session) throws Pip
addSessionKey(session, sessionKeyName, null);
}
MimeType mimeType = (MimeType) bodyPartMessage.getContext().get(MessageContext.METADATA_MIMETYPE);
partsString.append("<part type=\"file\" name=\"" + fileName + "\" sessionKey=\"" + sessionKeyName + "\" size=\"" + size + "\" mimeType=\"" + mimeType + "\"/>");
partsString.append("<part type=\"file\" name=\"").append(fileName).append("\" sessionKey=\"").append(sessionKeyName).append("\" size=\"").append(size).append("\" mimeType=\"").append(mimeType).append("\"/>");
lastFoundFileName = fileName;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public Message getMessage(ICorrelatedPullingListener<M> listener, String correla

protected String getLogPrefix(ICorrelatedPullingListener<M> listener, PipeLineSession session){
StringBuilder sb = new StringBuilder();
sb.append("Listener [" + listener.getName() + "] ");
sb.append("Listener [").append(listener.getName()).append("] ");
if (session != null) {
sb.append("msgId [" + session.getMessageId() + "] ");
sb.append("msgId [").append(session.getMessageId()).append("] ");
}
return sb.toString();
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/frankframework/scheduler/JobDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,10 @@ protected String getLogPrefix() {
@Override
public String toString() {
StringBuilder builder = new StringBuilder(this.getClass().getSimpleName());
if(name != null) builder.append(" name ["+name+"]");
if(jobGroup != null) builder.append(" jobGroup ["+jobGroup+"]");
if(cronExpression != null) builder.append(" cronExpression ["+cronExpression+"]");
if(interval > -1) builder.append(" interval ["+interval+"]");
if (name != null) builder.append(" name [").append(name).append("]");
if (jobGroup != null) builder.append(" jobGroup [").append(jobGroup).append("]");
if (cronExpression != null) builder.append(" cronExpression [").append(cronExpression).append("]");
if (interval > -1) builder.append(" interval [").append(interval).append("]");
return builder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void execute() throws JobExecutionException, TimeoutException {
@Override
public String toString() {
StringBuilder builder = new StringBuilder(super.toString());
if(function != null) builder.append(" function ["+function+"]");
if(function != null) builder.append(" function [").append(function).append("]");
return builder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ public void setRecipientsOnMessage(StringBuilder logBuffer) throws SenderExcepti
if(isRecipientWhitelisted(recipient)) {
addRecipientToMessage(recipient);
if (log.isDebugEnabled()) {
logBuffer.append("[recipient [" + recipient + "]]");
logBuffer.append("[recipient [").append(recipient).append("]]");
}
} else {
log.warn("Recipient [" + recipient + "] ignored, not in domain whitelist [" + getDomainWhitelist() + "]");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.frankframework.collection;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.frankframework.core.PipeLineSession;
import org.frankframework.senders.SenderTestBase;
Expand Down Expand Up @@ -28,7 +29,7 @@ void testWrite() throws Exception {
String input = "testWrite";
sendMessage(input);

assertEquals(true, collector.open);
assertTrue(collector.open);
assertEquals(input, collector.getInput());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testWrite() throws Exception {
assertEquals("success", prr.getPipeForward().getName());
assertEquals("testWrite", collector.getInput());
assertNull(prr.getResult().asString());
assertEquals(true, collector.open);
assertTrue(collector.open);
}

@Test
Expand Down
Loading

0 comments on commit 7e294ea

Please sign in to comment.