Skip to content

TG-23049 - added new attributes to @InTestsMock #30

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

Merged
merged 1 commit into from
May 15, 2025
Merged
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
50 changes: 37 additions & 13 deletions src/main/java/com/diffblue/cover/annotations/InTestsMock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Diffblue Limited.
* Copyright 2024-2025 Diffblue Limited.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,7 @@
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PACKAGE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.CLASS;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
Expand All @@ -32,29 +32,53 @@
*
* @since Diffblue Cover 2024.04.02
*/
@Retention(CLASS)
@Retention(RUNTIME)
@Target({PACKAGE, TYPE, METHOD})
@Repeatable(InTestsMock.Repeatable.class)
public @interface InTestsMock {

/** Collects multiple {@link InTestsMock} annotations. */
@Retention(CLASS)
@Retention(RUNTIME)
@Target({PACKAGE, TYPE, METHOD})
@interface Repeatable {

/**
* @return the repeated {@link InTestsMock} annotations.
*/
/** @return the repeated {@link InTestsMock} annotations. */
InTestsMock[] value();
}

/**
* @return the classes to mock (or not).
*/
/** @return the classes to mock (or not). */
Class<?>[] value();

/**
* @return the mocking decision to apply.
*/
/** @return the mocking decision to apply. */
MockDecision decision() default RECOMMENDED;

/** @return name of method to mock */
String method() default "";

/** @return boolean value or values to return from the {@link #method()} */
boolean[] booleanReturnValues() default {};

/** @return byte value or values to return from the {@link #method()} */
byte[] byteReturnValues() default {};

/** @return char value or values to return from the {@link #method()} */
char[] charReturnValues() default {};

/** @return float value or values to return from the {@link #method()} */
float[] floatReturnValues() default {};

/** @return double value or values to return from the {@link #method()} */
double[] doubleReturnValues() default {};

/** @return int value or values to return from the {@link #method()} */
int[] intReturnValues() default {};

/** @return long value or values to return from the {@link #method()} */
long[] longReturnValues() default {};

/** @return short value or values to return from the {@link #method()} */
short[] shortReturnValues() default {};

/** @return String value or values to return from the {@link #method()} */
String[] stringReturnValues() default {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we cannot use: String[][] can we do:
String[] stringArrayReturnValue - to return only one array. does it make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would support 1-D arrays. We would have to add similar attributes for each of the primitive types as well. @peterschrammel should we do this?

}