Skip to content

Commit

Permalink
- Cleanup some of the more trivial PMD warnings and suppress where
Browse files Browse the repository at this point in the history
appropriate

Issue: dsldevkit#22
  • Loading branch information
[email protected] authored and [email protected] committed Dec 21, 2017
1 parent a96bdcd commit 6abd547
Show file tree
Hide file tree
Showing 24 changed files with 87 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ private String getNormalizedContents(final Class<? extends AbstractCheckTestCase
* @param project
* to list
*/
@SuppressWarnings("PMD.InsufficientStringBufferDeclaration")
protected void enumerateContents(final IProject project) {
try {
final StringBuilder b = new StringBuilder();
Expand All @@ -403,7 +404,7 @@ protected void enumerateContents(final IProject project) {
@SuppressWarnings("deprecation")
public boolean visit(final IResource rsc) throws CoreException {
String filePath = rsc.getFullPath().toString();
b.append(filePath + (rsc instanceof IFolder ? "/" : "") + '\n');
b.append(filePath).append(rsc instanceof IFolder ? "/" : "").append('\n');
if (rsc instanceof IFile && !filePath.contains("/bin/") && !filePath.endsWith("._trace")) {
IFile file = (IFile) rsc;
b.append("---- Content:\n");
Expand All @@ -412,7 +413,7 @@ public boolean visit(final IResource rsc) throws CoreException {
s = new InputStreamReader(file.getContents());
b.append(CharStreams.toString(s));
} catch (IOException e) {
b.append("**** ERROR:" + e.getMessage());
b.append("**** ERROR:").append(e.getMessage());
} finally {
Closeables.closeQuietly(s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ public void assertEmpty() {
throw (Error) problem;
}
}
printStackTrace();
printStackTrace(); // NOPMD
throw this;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

/**
* Representation of a step result.
*
*
* @param <T>
* the type of the result value
*/
Expand All @@ -22,7 +22,7 @@ public final class StepResult<T> implements IStepData<T> {

/**
* Creates and returns a {@link StepResult}.
*
*
* @param <T>
* the type of the step result value
* @return the newly created {@link StepResult}
Expand All @@ -39,17 +39,18 @@ private StepResult() {
}

/** {@inheritDoc} */
@Override
public T getValue() {
return value;
}

/**
* Sets the value of this {@link StepResult}. This can only be done by the test framework.
*
*
* @param value
* the new value for this {@link StepResult}
*/
protected void setValue(final T value) {
void setValue(final T value) {
// currently we set the result multiple time until the postconditions succeed. Hence we cannot enforce this anymore.
// XXX : think about refactoring so that we can check the following assertion again, or decide to remove it for good.
// Assert.assertFalse("Step result value must not have been set yet.", valueSet);
Expand All @@ -58,6 +59,7 @@ protected void setValue(final T value) {
}

/** {@inheritDoc} */
@Override
public boolean isValueSet() {
return valueSet;
}
Expand All @@ -72,4 +74,3 @@ public String toString() {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ private void runRepeatedly(final FrameworkMethod method, final EachTestNotifier
final MultipleTestProblems problems = new MultipleTestProblems();
final Collection<AssertionError> failures = Lists.newArrayList();
final Collection<Throwable> errors = Lists.newArrayList();
final String testCase = getTestClass().getJavaClass().getSimpleName() + "." + method.getName();
int run = 0;
int succeeded = 0;
while (run < testRuns || (testRuns == 1 && succeeded == 0 && run < testRetries + 1)) {
Expand All @@ -227,6 +226,7 @@ private void runRepeatedly(final FrameworkMethod method, final EachTestNotifier
problems.addProblem(throwable);
}
}
final String testCase = getTestClass().getJavaClass().getSimpleName() + '.' + method.getName();
if (run > 1) {
logRepeatedTestResult(testCase, run, succeeded, failures.size(), errors.size());
}
Expand Down Expand Up @@ -283,7 +283,7 @@ public void logRepeatedTestResult(final String testCase, final int runs, final i
if (errors > 0) {
testResult.append(", ").append(errors).append(" errored");
}
testResult.append(")");
testResult.append(')');
LOGGER.info(testResult.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class DiscerningSuite extends Suite {

/**
* Creates a new instance of {@link DiscerningSuite}.
*
*
* @param klass
* root of the suite
* @param runners
Expand All @@ -48,22 +48,22 @@ public DiscerningSuite(final Class<?> klass, final List<Runner> runners) throws

/**
* Creates a new instance of {@link DiscerningSwtBotNonSwtBotSuite}.
*
*
* @param klass
* the root of the suite
* @param suiteClasses
* the classes in the suite
* @throws InitializationError
* if an error occurred during the initialization
*/
public DiscerningSuite(final Class<?> klass, final Class<?>[] suiteClasses) throws InitializationError {
public DiscerningSuite(final Class<?> klass, final Class<?>... suiteClasses) throws InitializationError {
super(klass, suiteClasses);
initialize();
}

/**
* Creates a new instance of {@link DiscerningSwtBotNonSwtBotSuite}.
*
*
* @param klass
* the root class
* @param builder
Expand All @@ -78,7 +78,7 @@ public DiscerningSuite(final Class<?> klass, final RunnerBuilder builder) throws

/**
* Creates a new instance of {@link DiscerningSwtBotNonSwtBotSuite}.
*
*
* @param builder
* builds runners for classes in the suite
* @param klass
Expand All @@ -88,22 +88,22 @@ public DiscerningSuite(final Class<?> klass, final RunnerBuilder builder) throws
* @throws InitializationError
* if an error occurred during the initialization
*/
public DiscerningSuite(final RunnerBuilder builder, final Class<?> klass, final Class<?>[] suiteClasses) throws InitializationError {
public DiscerningSuite(final RunnerBuilder builder, final Class<?> klass, final Class<?>... suiteClasses) throws InitializationError {
super(builder, klass, suiteClasses);
initialize();
}

/**
* Creates a new instance of {@link DiscerningSwtBotNonSwtBotSuite}.
*
*
* @param builder
* builds runners for classes in the suite
* @param classes
* the classes in the suite
* @throws InitializationError
* if an error occurred during the initialization
*/
public DiscerningSuite(final RunnerBuilder builder, final Class<?>[] classes) throws InitializationError {
public DiscerningSuite(final RunnerBuilder builder, final Class<?>... classes) throws InitializationError {
super(builder, classes);
initialize();
}
Expand Down Expand Up @@ -141,4 +141,3 @@ public void filter(final Filter filter) throws NoTestsRemainException {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ public DynamicSuite(final Class<?> clazz, final RunnerBuilder builder) throws In
this(clazz, builder.runners(clazz, getSuiteClasses(clazz)));
}

public DynamicSuite(final RunnerBuilder builder, final Class<?>[] classes) throws InitializationError {
public DynamicSuite(final RunnerBuilder builder, final Class<?>... classes) throws InitializationError {
super(builder, classes);
}

public DynamicSuite(final Class<?> clazz, final Class<?>[] suiteClasses) throws InitializationError {
public DynamicSuite(final Class<?> clazz, final Class<?>... suiteClasses) throws InitializationError {
super(clazz, suiteClasses);
}

public DynamicSuite(final Class<?> clazz, final List<Runner> runners) throws InitializationError {
super(clazz, runners);
}

public DynamicSuite(final RunnerBuilder builder, final Class<?> clazz, final Class<?>[] suiteClasses) throws InitializationError {
public DynamicSuite(final RunnerBuilder builder, final Class<?> clazz, final Class<?>... suiteClasses) throws InitializationError {
super(builder, clazz, suiteClasses);
}

/**
* Collect suite classes from annotation.
*
*
* @param clazz
* main suite to get suite classes annotation from
* @return list of suite classes
Expand Down Expand Up @@ -90,4 +90,3 @@ private static Class<?>[] getSuiteClasses(final Class<?> clazz) throws Initializ
return suiteClasses.toArray(new Class<?>[suiteClasses.size()]);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,10 @@ private String describeFilters(final List<Filter> filters, final String title) {
if (!filters.isEmpty()) {
description.append(" (").append(title).append(" filters:");
for (final Filter filter : filters) {
description.append(" ").append(filter.describe());
description.append(' ').append(filter.describe());
}
description.append(")");
description.append(')');
}
return description.toString();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private ExtensionRegistryMock() {}
* @throws CoreException
*/
@SuppressWarnings("restriction") // for accessing RegistryProviderFactory
public static void mockRegistry() {
public static synchronized void mockRegistry() {
if (registrySpy == null) {
registry = RegistryFactory.getRegistry();
registrySpy = spy(registry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ public static String generateUniqueName(final String namePrefix) {
* @return the random string
*/
public static String randomAlphanumericString(final int count) {
String string = RandomStringUtils.randomAlphabetic(1);
StringBuilder stringBuilder = new StringBuilder(RandomStringUtils.randomAlphabetic(1));
if (count > 1) {
string = string + RandomStringUtils.randomAlphanumeric(count - 1);
stringBuilder.append(RandomStringUtils.randomAlphanumeric(count - 1));

}
String string = stringBuilder.toString();
Assert.isNotNull(string, "string"); //$NON-NLS-1$
return string.toUpperCase(Locale.ENGLISH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ private BufferedImage capture() {
*
* @return the call stack with test status information, never {@code null}
*/
@SuppressWarnings("PMD.InsufficientStringBufferDeclaration")
private String captureCallStack() {
StringBuilder trace = new StringBuilder();
// Same info as on the screenshot
Expand Down Expand Up @@ -398,8 +399,7 @@ private static Set<Long> getDeadlockThreadIds() {
* @return the owned lock information
*/
private static String getOwnedLockInfo(final ThreadInfo info) {
StringBuilder trace = new StringBuilder();
trace.append(" Holding locks for:\r\n");
StringBuilder trace = new StringBuilder(" Holding locks for:\r\n");
for (LockInfo lock : info.getLockedSynchronizers()) {
trace.append(" " + lock.toString() + "\r\n");
}
Expand All @@ -416,9 +416,9 @@ private static String getOwnedLockInfo(final ThreadInfo info) {
* the {@code:ThreadInfo} for the thread in question, must not be {@code:null}
* @return the thread stack trace
*/
@SuppressWarnings("PMD.InsufficientStringBufferDeclaration")
private static String getCallStackTrace(final ThreadInfo info) {
StringBuilder trace = new StringBuilder();
trace.append(" Stack:\r\n");
StringBuilder trace = new StringBuilder(" Stack:\r\n");
int frameCount = 0;
for (StackTraceElement frame : info.getStackTrace()) {
trace.append(" " + frame.toString() + "\r\n");
Expand All @@ -437,18 +437,17 @@ private static String getCallStackTrace(final ThreadInfo info) {
* @return the thread info
*/
private static String getThreadInfo() {
StringBuilder trace = new StringBuilder();
boolean contention = THREAD_BEAN.isThreadContentionMonitoringEnabled();
Set<Long> deadlockedThreads = getDeadlockThreadIds();
ThreadInfo[] threadInfos = THREAD_BEAN.dumpAllThreads(true, true);
trace.append(threadInfos.length + " active threads\r\n");
StringBuilder trace = new StringBuilder(threadInfos.length).append(" active threads\r\n");
for (ThreadInfo info : threadInfos) {
if (info == null) {
trace.append(" Inactive\r\n");
continue;
}
boolean isDeadlocked = deadlockedThreads.contains(Long.valueOf(info.getThreadId()));
trace.append("Thread " + getTaskName(info.getThreadId(), info.getThreadName()));
trace.append("Thread ").append(getTaskName(info.getThreadId(), info.getThreadName()));
if (isDeadlocked) {
trace.append(" <<DEADLOCK>>");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public static void waitForTableItem(final SWTWorkbenchBot bot, final SWTBotTable
* to look for items in, must not be {@code null}
* @return list of tree items, never {@code null}
*/
public static java.util.List<SWTBotTreeItem> treeItems(final SWTWorkbenchBot bot, final SWTBotTree tree) {
public static List<SWTBotTreeItem> treeItems(final SWTWorkbenchBot bot, final SWTBotTree tree) {
Assert.isNotNull(bot, ARGUMENT_BOT);
Assert.isNotNull(tree, ARGUMENT_TREE);
waitForTreeItem(bot, tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class SwtWorkbenchBot extends SWTWorkbenchBot {
private static final int DELAY_WIZARD_PAGE = 1000;
private static final String TIMEOUT_MSG = "Timeout of {0} ms reached while waiting for Button {1} to become active";

private ImpatientSwtWorkbenchBot fastBot;
private ImpatientSwtWorkbenchBot impatientBot;

@Override
public void closeAllShells() {
Expand Down Expand Up @@ -593,10 +593,10 @@ public void closePreferencePage() {
* @return the fast bot, never {@code null}
*/
public SWTWorkbenchBot fastBot() {
if (fastBot == null) {
fastBot = new ImpatientSwtWorkbenchBot();
if (impatientBot == null) {
impatientBot = new ImpatientSwtWorkbenchBot();
}
return fastBot;
return impatientBot;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@
public class AnyWidgetMatcher extends BaseMatcher<Widget> {

/** {@inheritDoc} */
@Override
public boolean matches(final Object item) {
if (item instanceof Widget) {
return true;
}
return false;
return item instanceof Widget;
}

/** {@inheritDoc} */
@Override
public void describeTo(final Description description) {
description.appendText("any widget not null");
}

/**
* Convenience method to obtain a matcher of this type.
*
*
* @return the base matcher
*/
public static BaseMatcher<Widget> anyWidget() {
Expand Down
Loading

0 comments on commit 6abd547

Please sign in to comment.