Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Certain test cases may only run if API version is high enough. Adding…
… support for defining such cases
- Loading branch information
Showing
6 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/java/de/plushnikov/ApiVersionAwareLightCodeInsightFixureTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package de.plushnikov; | ||
|
||
import com.intellij.openapi.application.ApplicationInfo; | ||
import com.intellij.openapi.util.BuildNumber; | ||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; | ||
import com.intellij.util.ReflectionUtil; | ||
|
||
/** | ||
* Simple extension of {@link LightCodeInsightFixtureTestCase} that allows skipping test cases | ||
* based on required Platform API version. | ||
* | ||
* @author Alexej Kubarev | ||
*/ | ||
public abstract class ApiVersionAwareLightCodeInsightFixureTestCase extends LightCodeInsightFixtureTestCase { | ||
|
||
private String getMinVersion() { | ||
RequiredApiVersion requiredVersionAnnotation = getClass().getAnnotation(RequiredApiVersion.class); | ||
if (requiredVersionAnnotation != null) { | ||
return requiredVersionAnnotation.value(); | ||
} | ||
return getCurrentVersion().asStringWithoutProductCodeAndSnapshot(); | ||
} | ||
|
||
@Override | ||
protected void runTest() throws Throwable { | ||
|
||
// Minimal API Version for these tests to pass | ||
BuildNumber required = BuildNumber.fromString(getMinVersion()); | ||
if (getCurrentVersion().compareTo(required) >= 0) { | ||
super.runTest(); | ||
} | ||
} | ||
|
||
private BuildNumber getCurrentVersion() { | ||
return ApplicationInfo.getInstance().getBuild(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package de.plushnikov; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Defines that a test class may only run if the current API version is at least the given value. | ||
* Requires a test class to extend {@link ApiVersionAwareLightCodeInsightFixureTestCase}, as it contains conditional logic. | ||
* Additional base classes may be added in the same way. | ||
* | ||
* @author Alexej Kubarev | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface RequiredApiVersion { | ||
|
||
String value(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters