Skip to content

Commit

Permalink
IDE-250 Fix all PMD warnings (#5007)
Browse files Browse the repository at this point in the history
* IDE-250 Fix all PMD warnings

* IDE-250 Move ServiceProviderTestService to separate file

* IDE-250 Fix warnings

* IDE-250 Suppress PMD warning for class TestService
  • Loading branch information
coki1405 authored Nov 16, 2024
1 parent 43e8609 commit f073a63
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 97 deletions.
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
Expand Up @@ -165,7 +165,6 @@ public void setMaxViewPort(Resolution maxViewPort) {

private static final int Z_LAYER_PEN_ACTOR = 1;
private static final int Z_LAYER_EMBROIDERY_ACTOR = 2;
private static final int Z_LAYER_PLOT_ACTOR = 3;

private Map<String, StageBackup> stageBackupMap = new HashMap<>();

Expand Down Expand Up @@ -527,11 +526,13 @@ public void render() {

if (reloadProject) {
stage.clear();
if (penActor != null)
if (penActor != null) {
penActor.dispose();
}

if (plotActor != null)
if (plotActor != null) {
plotActor.dispose();
}

embroideryPatternManager.clear();

Expand Down Expand Up @@ -714,11 +715,13 @@ public void dispose() {
SoundManager.getInstance().clear();
PhysicsShapeBuilder.getInstance().reset();
embroideryPatternManager = null;
if (penActor != null)
if (penActor != null) {
penActor.dispose();
}

if(plotActor != null)
if(plotActor != null) {
plotActor.dispose();
}
}

public void finish() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@
import org.catrobat.catroid.R;
import org.catrobat.catroid.common.FlavoredConstants;
import org.catrobat.catroid.common.LookData;
import org.catrobat.catroid.content.Script;
import org.catrobat.catroid.content.Sprite;
import org.catrobat.catroid.content.StartScript;
import org.catrobat.catroid.content.bricks.MoveNStepsBrick;
import org.catrobat.catroid.content.bricks.PenDownBrick;
import org.catrobat.catroid.content.bricks.PlaceAtBrick;
import org.catrobat.catroid.content.bricks.RepeatBrick;
import org.catrobat.catroid.content.bricks.RepeatUntilBrick;
import org.catrobat.catroid.content.bricks.SetTransparencyBrick;
import org.catrobat.catroid.content.bricks.TurnRightBrick;
import org.catrobat.catroid.io.ResourceImporter;
Expand All @@ -43,12 +40,14 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.catrobat.catroid.common.Constants.DEFAULT_IMAGE_EXTENSION;
import static org.catrobat.catroid.common.Constants.IMAGE_DIRECTORY_NAME;

public final class ActorsAndObjectsManager {

private static ActorsAndObjectsManager instance = null;

public static ActorsAndObjectsManager getInstance() {
if (instance == null) {
instance = new ActorsAndObjectsManager();
Expand All @@ -62,14 +61,15 @@ private ActorsAndObjectsManager() {
private Sprite generateSprite(String name, int imgId, double scale) throws IOException {
var sprite = new Sprite(name);
var folder = new File(FlavoredConstants.DEFAULT_ROOT_DIRECTORY, IMAGE_DIRECTORY_NAME);
if(!folder.exists())
if (!folder.exists()) {
folder.mkdirs();
}
var path =
ResourceImporter.createImageFileFromResourcesInDirectory(ProjectManager.getInstance().getApplicationContext().getResources(),
imgId,
folder,
"img" + DEFAULT_IMAGE_EXTENSION,
scale);
"img" + DEFAULT_IMAGE_EXTENSION,
scale);
var lookData = new LookData(name, path);
sprite.getLookList().add(lookData);

Expand All @@ -80,7 +80,7 @@ public List<Sprite> getSprites() {
var sprites = new ArrayList<Sprite>();

try {
if(SettingsFragment.isEmroiderySharedPreferenceEnabled(ProjectManager.getInstance().getApplicationContext())){
if (SettingsFragment.isEmroiderySharedPreferenceEnabled(ProjectManager.getInstance().getApplicationContext())) {
var frame = generateSprite("10x10", R.drawable.frame, 1.0);
var script = new StartScript();
script.addBrick(new SetTransparencyBrick(100.0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;

Expand Down Expand Up @@ -100,11 +99,6 @@ public void onStop() {
finishActionMode();
}

@Override
public void onPrepareOptionsMenu(Menu menu) {
super.onPrepareOptionsMenu(menu);
}

protected void finishActionMode() {
adapter.clearSelection();
setShowProgressBar(false);
Expand All @@ -113,7 +107,6 @@ protected void finishActionMode() {
@Override
public void onItemClick(final T item, MultiSelectionManager selectionManager) {
unpackItems(new ArrayList<>(Collections.singletonList(item)));

}

public void setShowProgressBar(boolean show) {
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 @@ -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();
}
}

0 comments on commit f073a63

Please sign in to comment.