exercism / java-test-runner

GNU Affero General Public License v3.0
9 stars 13 forks source link

Remote Control Competition does not compile tests #31

Closed rvaughan74 closed 2 years ago

rvaughan74 commented 3 years ago

I get the following message from Exercism but not my local machine.

We received the following error when we ran your code: Note: /opt/test-runner/lib/remote-control-competition/src/main/java/ProductionRemoteControlCar.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Note: /opt/test-runner/lib/remote-control-competition/src/main/java/TestTrack.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details.

My Local machine version

vaughan@localhost:~$ java -version openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment (build 11.0.11+9-Ubuntu-0ubuntu2.20.04) OpenJDK 64-Bit Server VM (build 11.0.11+9-Ubuntu-0ubuntu2.20.04, mixed mode, sharing)

jmrunkle commented 3 years ago

What does the code in question look like?

rvaughan74 commented 3 years ago
class ProductionRemoteControlCar implements RemoteControlCar, Comparable<ProductionRemoteControlCar> {
    private int distance;
    private int victories;
    private final int driveDistance = 10;

    public ProductionRemoteControlCar() {

        this.distance = 0;
        this.victories = 0;
    }

    public void drive() {

        this.distance += driveDistance;
    }

    public int getDistanceTravelled() {

        return this.distance;
    }

    public int getNumberOfVictories() {

        return this.victories;
    }

    public void setNumberOfVictories(int numberofFictories) {

        this.victories = numberofFictories;
    }

    public int compareTo(ProductionRemoteControlCar y) {

        Integer xVictories = new Integer(this.victories);
        Integer yVictories = new Integer(y.getNumberOfVictories());

        return xVictories.compareTo(yVictories);
    }
}
jmrunkle commented 3 years ago

OK, so that code does in fact use a deprecated API: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Integer.html#%3Cinit%3E(int)

Creating new boxed primitive types using their constructors is a bad practice for the reasons described in the Javadoc. You should use Integer.valueOf instead if you need to create the boxed version.

That being said, in that exercise you can just return this.victories - y.victories.

NOTE: We are currently re-writing the Java test runner so the exact output may change soon. See #29

rvaughan74 commented 3 years ago

Oops... surprised my local JVM didn't throw an exception.