No test generated

I was trying to generate a unit test for the following class:

@Value
@Accessors(fluent = true)
public class RelationAnnotation<T> implements Annotation {

  T type;

  Reference<?> left;

  Reference<?> right;

  public RelationAnnotation(
      @NotNull T type, @NotNull Reference<?> left, @NotNull Reference<?> right) {
    this.type = type;
    this.right = right;
    this.left = left;
  }
}

I was expecting a unit test verifying whether an exception occurred when one of the input parameters was null but instead I got the message that DiffBlue was not able to generate a unit class.

Hi @msche,

Thanks for getting in touch - I am sorry that we were unable to write a test for this method ‘out-of-the-box’. We have discussed internally and at first glance it looks like Diffblue Cover doesn’t currently identify @Accessors(fluent = true) as observers.

We are doing a quick test and I will get back to you today with more information

Thank you for your patience

Matthew
Diffblue

Hi @msche

I was able to write tests using Cover with your sample code, once I removed implements Annotation. Does your Annotation interface define some methods that need to be implemented? If so then you’ll need to ensure that the the methods are implemented in your class so that it can be successfully compiled and tests written. If you’re still having problems then please give us a little more information about the Annotation interface and indicate which version of Cover you’re using.

It’s also worth clarifying that Cover won’t write tests for null parameters simply because the @NotNull annotation is present. These annotations are present for the compiler and IDE to use, and don’t affect the behaviour of the code. Cover writes tests based on the behaviour of the code which in this case is just the same with or without null parameters. If your code explicitly behaves differently with null parameters, e.g with the following check, then Cover will try and capture that behaviour in a test:

    if (type == null) {
      throw new IllegalArgumentException("Type cannot be null");
    }

Hope that helps,

Rob

Hereby the Annotation interface:

package org.uniknow.olie.model;

public interface Annotation {}

As you can see there are no methods that require to be implemented.

Regarding the remarks about @NonNull. We are using aspectJ to weave nonnull checks in the generated classes during compile time. That makes me wonder. Is DiffBlue analyzing the java code or the classes?

ps: I’m using the community intelij plugin, version 3.33 in combination with Java 11