A
A
Artem Vereschaka2015-12-13 22:47:28
Java
Artem Vereschaka, 2015-12-13 22:47:28

What is the problem with C4J framework?

Hello.
So, it was necessary to sketch an example using the C4J framework.
Wrote a class

package ua.avereschaka.Utils;

import de.vksi.c4j.ContractReference;
import ua.avereschaka.Contracts.PhysicsUtilsContract;

@ContractReference(PhysicsUtilsContract.class)
public class PhysicsUtils {

    public double getMinSpeed(double busSpeed, double distToBus, double distToRoad){
        return (busSpeed * distToRoad) / distToBus;
    }

}

After that, naturally, a contract for him
package ua.avereschaka.Contracts;

import de.vksi.c4j.Contract;
import de.vksi.c4j.Target;
import ua.avereschaka.Utils.PhysicsUtils;

import static de.vksi.c4j.Condition.*;

@Contract
public class PhysicsUtilsContract extends PhysicsUtils {

    @Target
    private PhysicsUtils target;

    @Override
    public double getMinSpeed(double busSpeed, double distToBus, double distToRoad) {
        if (preCondition()) {
            assert busSpeed >= 0;
            assert distToBus >= 0;
            assert distToRoad >= 0;
        }
        if (postCondition()) {
            assert result() != null;
            assert result(Double.class) >= 0;
        }
        return ignored();
    }
}

I start with incorrect parameters (for example, I pass a negative busSpeed) and it works fine.
What is the problem?
I use IDEA 15, I connected the jar file through project settings, because this C4J is not in Maven.
Poke, please, where should I move, or point out a clear error in the code.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Vereschaka, 2015-12-13
@And3en

UPD: SOLVED
Specified javaagent to C4J jar nickname in startup parameters, and enabled assertions:
-javaagent:c4j-6.0.0.jar -ea

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question