Skip to content
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

v1.2.0 #67

Merged
merged 8 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
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
60 changes: 0 additions & 60 deletions .github/workflows/run-ui-tests.yml

This file was deleted.

8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@

## [Unreleased]

## [1.2.0]
### Changed
- New support range of IDEs: 2023.3-2024.2-EAP.
- Dependency updates.

### Fixed
- Fixed an exception that occurred during previewing the quick fix result for simplifying mock creations.

## [1.1.0]
### Changed
- New support range of IDEs: 2023.1.5-2024.1-EAP.
Expand Down
11 changes: 2 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,11 @@ Other resources: [IntelliJ Platform Plugin SDK - Testing Overview](https://plugi

#### JDK

Java file based tests require either a mock or a real JDK to be available. This project is configured to always use a real JDK via
`com.picimako.mockitools.MockitoolsTestBase#getJdkHome()`, so that modification of the
Java file based tests require either a mock or a real JDK to be available. This project is configured to always use a real JDK,
so that modification of the
[`idea.home.path` system property](https://plugins.jetbrains.com/docs/intellij/code-inspections.html#inspection-unit-test)
is not necessary for running tests locally. And, using the JAVA_HOME based JDK also works on GitHub Actions.

#### Other libs

In order for tests to recognize code from other libraries, those libraries have to be added to the classpath too. You can use the various
`load*()` methods of `com.picimako.mockitools.ThirdPartyLibraryLoader`.

These libraries are located in the `lib` directory under the project root.

### testData

The `src/test/testData` folder is used to store test data. They can be configured as project roots when setting the test data path in functional tests.
Expand Down
16 changes: 4 additions & 12 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,11 @@ changelog {
repositoryUrl = properties("pluginRepositoryUrl")
}

// Configure Gradle Qodana Plugin - read more: https://github.com/JetBrains/gradle-qodana-plugin
//qodana {
// cachePath = provider { file(".qodana").canonicalPath }
// reportPath = provider { file("build/reports/inspections").canonicalPath }
// saveReport = true
// showReport = environment("QODANA_SHOW_REPORT").map { it.toBoolean() }.getOrElse(false)
//}

dependencies {
testImplementation("org.assertj:assertj-core:3.25.2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.2")
testImplementation("org.assertj:assertj-core:3.26.0")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0")
}

tasks {
Expand Down
16 changes: 5 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

pluginGroup = com.picimako.mockitools
pluginName = Mockitools
pluginVersion = 1.1.0
pluginVersion = 1.2.0

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 231.9392.1
pluginUntilBuild = 241.*
pluginSinceBuild = 233.11799.241
pluginUntilBuild = 242.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
platformVersion = 2023.1.5
platformVersion = 2023.3

# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins = java

# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.5
gradleVersion = 8.7

# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib
kotlin.stdlib.default.dependency = false
Expand All @@ -27,9 +27,3 @@ org.gradle.configuration-cache = true

# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching = true

# Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment
systemProp.org.gradle.unsafe.kotlin.assignment = true

# Temporary workaround for Kotlin Compiler OutOfMemoryError -> https://jb.gg/intellij-platform-kotlin-oom
kotlin.incremental.useClasspathSnapshot = false
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
# libraries
annotations = "24.0.1"
annotations = "24.1.0"

# plugins
kotlin = "1.9.0"
changelog = "2.1.0"
gradleIntelliJPlugin = "1.17.0"
lombok = "8.3"
changelog = "2.2.0"
gradleIntelliJPlugin = "1.17.3"
lombok = "8.6"

[libraries]
annotations = { group = "org.jetbrains", name = "annotations", version.ref = "annotations" }
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
22 changes: 13 additions & 9 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -130,26 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -198,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
Binary file removed lib/junit-4.13.2.jar
Binary file not shown.
Binary file removed lib/mockito-core-3.12.4.jar
Binary file not shown.
Binary file removed lib/mockito-core-4.11.0.jar
Binary file not shown.
Binary file removed lib/mockito-core-5.4.0.jar
Binary file not shown.
12 changes: 0 additions & 12 deletions qodana.yml

This file was deleted.

40 changes: 25 additions & 15 deletions src/main/java/com/picimako/mockitools/MockableTypesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
package com.picimako.mockitools;

import static com.intellij.codeInsight.AnnotationUtil.getStringAttributeValue;
import static com.intellij.openapi.application.ReadAction.compute;
import static com.intellij.psi.util.InheritanceUtil.getSuperClasses;
import static com.intellij.psi.util.TypeConversionUtil.isPrimitive;
import static com.intellij.psi.util.TypeConversionUtil.isPrimitiveWrapper;

import com.intellij.psi.CommonClassNames;
import com.intellij.psi.PsiAnnotation;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiClassType;
import com.intellij.psi.PsiType;
import com.intellij.psi.util.TypeConversionUtil;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
Expand Down Expand Up @@ -39,18 +41,18 @@ public final class MockableTypesUtil {
*/
public static Optional<DoNotMockType> getDoNotMockTypeInHierarchy(@Nullable PsiType type) {
if (type instanceof PsiClassType classType) {
PsiClass referencedClass = classType.resolve();
PsiClass referencedClass = compute(classType::resolve);
if (referencedClass != null) {
//Checks if the use class type is annotated
var doNotMock = getDoNotMockAnnotationOn(referencedClass);
if (doNotMock.isPresent()) {
return Optional.of(new DoNotMockType(getStringAttributeValue(doNotMock.get(), "reason")));
return Optional.of(new DoNotMockType(compute(() -> getStringAttributeValue(doNotMock.get(), "reason"))));
}
//If the direct class type is not annotated, proceeds to check all its super classes
for (PsiClass cls : getSuperClasses(referencedClass)) {
var doNotMockInHierarchy = getDoNotMockAnnotationOn(cls);
if (doNotMockInHierarchy.isPresent()) {
return Optional.of(new DoNotMockType(getStringAttributeValue(doNotMockInHierarchy.get(), "reason")));
return Optional.of(new DoNotMockType(compute(() -> getStringAttributeValue(doNotMockInHierarchy.get(), "reason"))));
}
}
}
Expand All @@ -59,11 +61,11 @@ public static Optional<DoNotMockType> getDoNotMockTypeInHierarchy(@Nullable PsiT
}

private static Optional<PsiAnnotation> getDoNotMockAnnotationOn(PsiClass clazz) {
return !CommonClassNames.JAVA_LANG_OBJECT.equals(clazz.getQualifiedName())
? Arrays.stream(clazz.getAnnotations())
.filter(annotation -> annotation.getQualifiedName().endsWith(MockitoQualifiedNames.ORG_MOCKITO_DO_NOT_MOCK))
.findFirst()
: Optional.empty();
return compute(() -> !CommonClassNames.JAVA_LANG_OBJECT.equals(clazz.getQualifiedName())
? Arrays.stream(clazz.getAnnotations())
.filter(annotation -> annotation.getQualifiedName().endsWith(MockitoQualifiedNames.ORG_MOCKITO_DO_NOT_MOCK))
.findFirst()
: Optional.empty());
}

/**
Expand All @@ -83,10 +85,18 @@ public static boolean isMockableTypeInAnyWay(@Nullable PsiType type) {
* @see #NON_MOCKABLE_TYPES
*/
public static boolean isMockableType(@Nullable PsiType type) {
return type != null
&& !TypeConversionUtil.isPrimitiveWrapper(type)
&& !TypeConversionUtil.isPrimitive(type.getCanonicalText())
&& !NON_MOCKABLE_TYPES.contains(type.getCanonicalText());
if (type != null) {
return compute(() -> {
if (compute(() -> !isPrimitiveWrapper(type))) {
String canonicalText = compute(type::getCanonicalText);
return compute(() -> !isPrimitive(canonicalText))
&& !NON_MOCKABLE_TYPES.contains(compute(type::getCanonicalText));
}
return false;
});
}

return false;
}

/**
Expand All @@ -98,10 +108,10 @@ public static boolean isMockableType(@Nullable PsiType type) {
*/
private static boolean isDoNotMockAnnotatedInHierarchy(@Nullable PsiType type) {
if (type instanceof PsiClassType classType) {
PsiClass referencedClass = classType.resolve();
PsiClass referencedClass = compute(classType::resolve);
if (referencedClass != null) {
return getDoNotMockAnnotationOn(referencedClass).isPresent()
|| getSuperClasses(referencedClass).stream().anyMatch(cls -> getDoNotMockAnnotationOn(cls).isPresent());
|| compute(() -> getSuperClasses(referencedClass).stream().anyMatch(cls -> getDoNotMockAnnotationOn(cls).isPresent()));
}
}
return false;
Expand Down
Loading
Loading