Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE-250 Fix all PMD warnings #5007

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -22,7 +22,6 @@
*/
package org.catrobat.catroid.test.common;

import org.catrobat.catroid.bluetooth.base.BluetoothDeviceService;
import org.catrobat.catroid.common.CatroidService;
import org.catrobat.catroid.common.ServiceProvider;
import org.junit.Test;
Expand All @@ -32,7 +31,6 @@

import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;

@RunWith(AndroidJUnit4.class)
public class ServiceProviderTest {
Expand All @@ -42,7 +40,6 @@ public void testCommonServices() {
CatroidService service = ServiceProvider.getService(CatroidService.BLUETOOTH_DEVICE_SERVICE);

assertNotNull(service);
assertTrue(service instanceof BluetoothDeviceService);
}

@Test
Expand All @@ -55,6 +52,7 @@ public void testRegisterAndGetService() {
assertNotNull(service);
}

@SuppressWarnings("PMD.TestClassWithoutTestCases")
private static class TestService implements CatroidService {
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -50,6 +50,7 @@

import static org.catrobat.catroid.common.Constants.SOUND_DIRECTORY_NAME;

@SuppressWarnings("PMD.TestClassWithoutTestCases")
public final class TestUtils {

public static final String DEFAULT_TEST_PROJECT_NAME = "testProject";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -53,7 +53,7 @@ protected void begin() {
return;
}
Double interpretation = ifCondition.interpretDouble(scope);
ifConditionValue = interpretation.intValue() <= DISTANCE_THRESHOLD_VALUE ? true : false;
ifConditionValue = interpretation.intValue() <= DISTANCE_THRESHOLD_VALUE;
isInterpretedCorrectly = true;
} catch (InterpretationException interpretationException) {
isInterpretedCorrectly = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -34,16 +34,7 @@

public class EV3Command implements MindstormsCommand {

private ByteArrayOutputStream commandData = new ByteArrayOutputStream();

public EV3Command(short commandCounter, EV3CommandType commandType, EV3CommandOpCode commandByte) {

commandData.write((byte) (commandCounter & 0x00FF));
commandData.write((byte) ((commandCounter & 0xFF00) >> 8));

commandData.write(commandType.getByte());
commandData.write(commandByte.getByte());
}
private final ByteArrayOutputStream commandData = new ByteArrayOutputStream();

public EV3Command(short commandCounter, EV3CommandType commandType, int globalVars, int localVars, EV3CommandOpCode commandByte) {

Expand Down Expand Up @@ -143,20 +134,4 @@ public int getLength() {
public byte[] getRawCommand() {
return commandData.toByteArray();
}

public String toHexString(EV3Command command) {
byte[] rawBytes = command.getRawCommand();
StringBuilder commandHexString = new StringBuilder("0x");

if (rawBytes.length == 0) {
return "0";
}

for (int i = 0; i < rawBytes.length; i++) {
commandHexString.append(Integer.toHexString(rawBytes[i] & 0xFF));
commandHexString.append("_");
}

return commandHexString.toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -26,7 +26,6 @@
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.Editable;
import android.widget.EditText;

import com.google.android.material.textfield.TextInputLayout;
Expand Down Expand Up @@ -134,39 +133,6 @@ public boolean isUnique(String newName) {
}
}

public abstract static class TextWatcher implements android.text.TextWatcher {

private TextInputLayout inputLayout;
private AlertDialog alertDialog;

private void setInputLayout(@NonNull TextInputLayout inputLayout) {
this.inputLayout = inputLayout;
}

private void setAlertDialog(@NonNull AlertDialog alertDialog) {
this.alertDialog = alertDialog;
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}

@Override
public void afterTextChanged(Editable s) {
String input = s.toString();
String error = validateInput(input, alertDialog.getContext());
inputLayout.setError(error);
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(error == null);
}

@Nullable
public abstract String validateInput(String input, Context context);
}

public interface OnClickListener {

void onPositiveButtonClick(DialogInterface dialog, String textInput);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -22,16 +22,16 @@
*/
package org.catrobat.catroid.test.physics;

import junit.framework.Assert;

import org.catrobat.catroid.physics.PhysicsWorldConverter;
import org.catrobat.catroid.test.utils.TestConstants;
import org.catrobat.catroid.test.utils.PhysicsWorldConverterAngleTestUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;

import static org.junit.Assert.assertEquals;

@RunWith(Parameterized.class)
public class PhysicsWorldConverterAngleTest {

Expand All @@ -55,11 +55,11 @@ public static Iterable<Object[]> data() {

@Test
public void testBox2dToNormalAngleConversion() {
Assert.assertEquals(deg, PhysicsWorldConverter.convertBox2dToNormalAngle(rad), TestConstants.DELTA);
assertEquals(deg, PhysicsWorldConverter.convertBox2dToNormalAngle(rad), PhysicsWorldConverterAngleTestUtils.DELTA);
}

@Test
public void testNormalToBox2dAngleConversion() {
Assert.assertEquals(rad, PhysicsWorldConverter.convertNormalToBox2dAngle(deg), TestConstants.DELTA);
assertEquals(rad, PhysicsWorldConverter.convertNormalToBox2dAngle(deg), PhysicsWorldConverterAngleTestUtils.DELTA);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Catroid: An on-device visual programming system for Android devices
* Copyright (C) 2010-2022 The Catrobat Team
* Copyright (C) 2010-2024 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -23,10 +23,10 @@

package org.catrobat.catroid.test.utils;

public final class TestConstants {
public final class PhysicsWorldConverterAngleTestUtils {
public static final double DELTA = 0.00001;

private TestConstants() {
private PhysicsWorldConverterAngleTestUtils() {
throw new AssertionError();
}
}