How to use Annotation Type Category class of org.junit.experimental.categories package

Best junit code snippet using org.junit.experimental.categories.Annotation Type Category

Source:Categories.java Github

copy

Full Screen

1/* 1: */ package org.junit.experimental.categories;2/* 2: */ 3/* 3: */ import java.lang.annotation.Annotation;4/* 4: */ import java.lang.annotation.Retention;5/* 5: */ import java.lang.annotation.RetentionPolicy;6/* 6: */ import java.util.ArrayList;7/* 7: */ import java.util.Arrays;8/* 8: */ import java.util.List;9/* 9: */ import org.junit.runner.Description;10/* 10: */ import org.junit.runner.manipulation.Filter;11/* 11: */ import org.junit.runner.manipulation.NoTestsRemainException;12/* 12: */ import org.junit.runners.Suite;13/* 13: */ import org.junit.runners.model.InitializationError;14/* 14: */ import org.junit.runners.model.RunnerBuilder;15/* 15: */ 16/* 16: */ public class Categories17/* 17: */ extends Suite18/* 18: */ {19/* 19: */ public static class CategoryFilter20/* 20: */ extends Filter21/* 21: */ {22/* 22: */ private final Class<?> fIncluded;23/* 23: */ private final Class<?> fExcluded;24/* 24: */ 25/* 25: */ public static CategoryFilter include(Class<?> categoryType)26/* 26: */ {27/* 27: 82 */ return new CategoryFilter(categoryType, null);28/* 28: */ }29/* 29: */ 30/* 30: */ public CategoryFilter(Class<?> includedCategory, Class<?> excludedCategory)31/* 31: */ {32/* 32: 91 */ this.fIncluded = includedCategory;33/* 33: 92 */ this.fExcluded = excludedCategory;34/* 34: */ }35/* 35: */ 36/* 36: */ public String describe()37/* 37: */ {38/* 38: 97 */ return "category " + this.fIncluded;39/* 39: */ }40/* 40: */ 41/* 41: */ public boolean shouldRun(Description description)42/* 42: */ {43/* 43:102 */ if (hasCorrectCategoryAnnotation(description)) {44/* 44:103 */ return true;45/* 45: */ }46/* 46:104 */ for (Description each : description.getChildren()) {47/* 47:105 */ if (shouldRun(each)) {48/* 48:106 */ return true;49/* 49: */ }50/* 50: */ }51/* 51:107 */ return false;52/* 52: */ }53/* 53: */ 54/* 54: */ private boolean hasCorrectCategoryAnnotation(Description description)55/* 55: */ {56/* 56:111 */ List<Class<?>> categories = categories(description);57/* 57:112 */ if (categories.isEmpty()) {58/* 58:113 */ return this.fIncluded == null;59/* 59: */ }60/* 60:114 */ for (Class<?> each : categories) {61/* 61:115 */ if ((this.fExcluded != null) && (this.fExcluded.isAssignableFrom(each))) {62/* 62:116 */ return false;63/* 63: */ }64/* 64: */ }65/* 65:117 */ for (Class<?> each : categories) {66/* 66:118 */ if ((this.fIncluded == null) || (this.fIncluded.isAssignableFrom(each))) {67/* 67:119 */ return true;68/* 68: */ }69/* 69: */ }70/* 70:120 */ return false;71/* 71: */ }72/* 72: */ 73/* 73: */ private List<Class<?>> categories(Description description)74/* 74: */ {75/* 75:124 */ ArrayList<Class<?>> categories = new ArrayList();76/* 76:125 */ categories.addAll(Arrays.asList(directCategories(description)));77/* 77:126 */ categories.addAll(Arrays.asList(directCategories(parentDescription(description))));78/* 78:127 */ return categories;79/* 79: */ }80/* 80: */ 81/* 81: */ private Description parentDescription(Description description)82/* 82: */ {83/* 83:131 */ Class<?> testClass = description.getTestClass();84/* 84:132 */ if (testClass == null) {85/* 85:133 */ return null;86/* 86: */ }87/* 87:134 */ return Description.createSuiteDescription(testClass);88/* 88: */ }89/* 89: */ 90/* 90: */ private Class<?>[] directCategories(Description description)91/* 91: */ {92/* 92:138 */ if (description == null) {93/* 93:139 */ return new Class[0];94/* 94: */ }95/* 95:140 */ Category annotation = (Category)description.getAnnotation(Category.class);96/* 96:141 */ if (annotation == null) {97/* 97:142 */ return new Class[0];98/* 98: */ }99/* 99:143 */ return annotation.value();100/* 100: */ }101/* 101: */ }102/* 102: */ 103/* 103: */ public Categories(Class<?> klass, RunnerBuilder builder)104/* 104: */ throws InitializationError105/* 105: */ {106/* 106:149 */ super(klass, builder);107/* 107: */ try108/* 108: */ {109/* 109:151 */ filter(new CategoryFilter(getIncludedCategory(klass), getExcludedCategory(klass)));110/* 110: */ }111/* 111: */ catch (NoTestsRemainException e)112/* 112: */ {113/* 113:154 */ throw new InitializationError(e);114/* 114: */ }115/* 115:156 */ assertNoCategorizedDescendentsOfUncategorizeableParents(getDescription());116/* 116: */ }117/* 117: */ 118/* 118: */ private Class<?> getIncludedCategory(Class<?> klass)119/* 119: */ {120/* 120:160 */ IncludeCategory annotation = (IncludeCategory)klass.getAnnotation(IncludeCategory.class);121/* 121:161 */ return annotation == null ? null : annotation.value();122/* 122: */ }123/* 123: */ 124/* 124: */ private Class<?> getExcludedCategory(Class<?> klass)125/* 125: */ {126/* 126:165 */ ExcludeCategory annotation = (ExcludeCategory)klass.getAnnotation(ExcludeCategory.class);127/* 127:166 */ return annotation == null ? null : annotation.value();128/* 128: */ }129/* 129: */ 130/* 130: */ private void assertNoCategorizedDescendentsOfUncategorizeableParents(Description description)131/* 131: */ throws InitializationError132/* 132: */ {133/* 133:170 */ if (!canHaveCategorizedChildren(description)) {134/* 134:171 */ assertNoDescendantsHaveCategoryAnnotations(description);135/* 135: */ }136/* 136:172 */ for (Description each : description.getChildren()) {137/* 137:173 */ assertNoCategorizedDescendentsOfUncategorizeableParents(each);138/* 138: */ }139/* 139: */ }140/* 140: */ 141/* 141: */ private void assertNoDescendantsHaveCategoryAnnotations(Description description)142/* 142: */ throws InitializationError143/* 143: */ {144/* 144:177 */ for (Description each : description.getChildren())145/* 145: */ {146/* 146:178 */ if (each.getAnnotation(Category.class) != null) {147/* 147:179 */ throw new InitializationError("Category annotations on Parameterized classes are not supported on individual methods.");148/* 148: */ }149/* 149:180 */ assertNoDescendantsHaveCategoryAnnotations(each);150/* 150: */ }151/* 151: */ }152/* 152: */ 153/* 153: */ private static boolean canHaveCategorizedChildren(Description description)154/* 154: */ {155/* 155:187 */ for (Description each : description.getChildren()) {156/* 156:188 */ if (each.getTestClass() == null) {157/* 157:189 */ return false;158/* 158: */ }159/* 159: */ }160/* 160:190 */ return true;161/* 161: */ }162/* 162: */ 163/* 163: */ @Retention(RetentionPolicy.RUNTIME)164/* 164: */ public static @interface ExcludeCategory165/* 165: */ {166/* 166: */ Class<?> value();167/* 167: */ }168/* 168: */ 169/* 169: */ @Retention(RetentionPolicy.RUNTIME)170/* 170: */ public static @interface IncludeCategory171/* 171: */ {172/* 172: */ Class<?> value();173/* 173: */ }174/* 174: */ }175176 177/* Location: G:\ParasiteTrade\Parasite_20150226.jar 178 * Qualified Name: org.junit.experimental.categories.Categories 179 * JD-Core Version: 0.7.0.1 ...

Full Screen

Full Screen

Source:ReplaceAllCategoryAction.java Github

copy

Full Screen

1import com.intellij.codeInsight.completion.AllClassesGetter;2import com.intellij.codeInsight.completion.PlainPrefixMatcher;3import com.intellij.openapi.actionSystem.AnAction;4import com.intellij.openapi.actionSystem.AnActionEvent;5import com.intellij.openapi.application.ApplicationManager;6import com.intellij.openapi.command.CommandProcessor;7import com.intellij.openapi.project.Project;8import com.intellij.psi.*;9import com.intellij.psi.codeStyle.JavaCodeStyleManager;10import com.intellij.psi.search.GlobalSearchScope;11import com.intellij.util.Processor;12import java.util.Arrays;13import java.util.List;14import java.util.Optional;15import java.util.stream.Collectors;16public class ReplaceAllCategoryAction extends AnAction {17 @Override18 public void actionPerformed(AnActionEvent e) {19 project = e.getProject();20 AllClassesGetter.processJavaClasses(21 new PlainPrefixMatcher(""),22 project,23 GlobalSearchScope.allScope(project),24 processor);25 }26 Processor<PsiClass> processor = psiClass -> {27 replaceCategory(psiClass);28 return true;29 };30 private Project project;31 private void replaceCategory(PsiClass psiClass) {32 Arrays.stream(psiClass.getMethods())33 .filter(m -> hasAnnotation(m, "org.junit.Test"))34 .filter(m -> hasAnnotation(m, "org.junit.experimental.categories.Category"))35 .forEach(this::replaceCategory);36 }37 private void replaceCategory(PsiMethod psiMethod) {38 PsiAnnotation name =39 psiMethod.getModifierList()40 .findAnnotation("org.junit.experimental.categories.Category");41 String value = name.42 findDeclaredAttributeValue("value").getText();43 List<String> techCategories = getTechCategories(value);44 String productCategory = getProductCategory(value);45 addFeature(psiMethod, productCategory);46 addTypes(psiMethod, techCategories);47 deleteCategory(psiMethod);48 }49 private void deleteCategory(PsiMethod psiMethod) {50 PsiAnnotation oldFeature =51 psiMethod.getModifierList()52 .findAnnotation("org.junit.experimental.categories.Category");53 CommandProcessor.getInstance().executeCommand(project, () ->54 ApplicationManager.getApplication().runWriteAction(() -> oldFeature.delete()), null, null);55 }56 private void addTypes(PsiMethod psiMethod, List<String> techCategories) {57 String text = getTypesAnnotation(techCategories);58 CommandProcessor.getInstance().executeCommand(project, () ->59 ApplicationManager.getApplication().runWriteAction(() -> {60 PsiAnnotation ann = createAnnotation(text, psiMethod);61 addAfterTest(ann, psiMethod);62 addImport(psiMethod.getContainingFile(), "com.wrike.annotation.Types");63 addImport(psiMethod.getContainingFile(), "com.wrike.annotation.Type");64 JavaCodeStyleManager.getInstance(project).shortenClassReferences(ann);65 }), null, null);66 }67 private void addAfterTest(PsiAnnotation psiAnnotation, PsiMethod psiMethod) {68 PsiAnnotation test = psiMethod.getModifierList().findAnnotation("org.junit.Test");69 psiMethod.getModifierList().addAfter(psiAnnotation, test);70 }71 private PsiAnnotation createAnnotation(String text, PsiMethod psiMethod) {72 return JavaPsiFacade.getInstance(project).getElementFactory().createAnnotationFromText(text, psiMethod);73 }74 private String getInnerType(List<String> feature) {75 return "{" + feature.stream().map(s -> "@Type(\"" + s + "\")").collect(Collectors.joining(",")) + "}";76 }77 private String getTypesAnnotation(List<String> feature) {78 String inner = getInnerType(feature);79 return "@Types(" + inner + ")";80 }81 private void addFeature(PsiMethod psiMethod, String productCategory) {82 String text = "io.qameta.allure.Feature(\"" + productCategory + "\")";83 CommandProcessor.getInstance().executeCommand(project, () ->84 ApplicationManager.getApplication().runWriteAction(() -> {85 PsiAnnotation ann = psiMethod.getModifierList().addAnnotation(text);86 JavaCodeStyleManager.getInstance(project).shortenClassReferences(ann);87 }), null, null);88 }89 private List<String> getTechCategories(String category) {90 List<String> tech = Arrays.asList("Smoke", "Firefox", "Safari");91 return Arrays.stream(category.substring(1, category.length() - 1)92 .split(", ")).map(s -> s.substring(0, s.indexOf('.')))93 .filter(tech::contains).collect(Collectors.toList());94 }95 private String getProductCategory(String category) {96 List<String> prod = Arrays.asList("Login", "Dashboard", "Inbox");97 return Arrays.stream(category.substring(1, category.length() - 1)98 .split(", "))99 .map(s -> s.substring(0, s.indexOf('.')))100 .filter(prod::contains).findFirst().get();101 }102 private boolean hasAnnotation(PsiMethod psiMethod, String annotationQualifiedName) {103 return Arrays.stream(psiMethod.getAnnotations())104 .anyMatch(psiAnnotation -> psiAnnotation.getQualifiedName().contains(annotationQualifiedName));105 }106 private void addImport(final PsiFile file, final String qualifiedName) {107 if (file instanceof PsiJavaFile) {108 addImport((PsiJavaFile) file, qualifiedName);109 }110 }111 private void addImport(final PsiJavaFile file, final String qualifiedName) {112 final Project project = file.getProject();113 Optional<PsiClass> possibleClass = Optional.ofNullable(JavaPsiFacade.getInstance(project)114 .findClass(qualifiedName, GlobalSearchScope.everythingScope(project)));115 possibleClass.ifPresent(psiClass -> JavaCodeStyleManager.getInstance(project).addImport(file, psiClass));116 }117}...

Full Screen

Full Screen

Source:ReplaceCategoryAction.java Github

copy

Full Screen

1import com.intellij.openapi.actionSystem.AnAction;2import com.intellij.openapi.actionSystem.AnActionEvent;3import com.intellij.openapi.application.ApplicationManager;4import com.intellij.openapi.command.CommandProcessor;5import com.intellij.openapi.project.Project;6import com.intellij.psi.*;7import com.intellij.psi.codeStyle.JavaCodeStyleManager;8import com.intellij.psi.search.GlobalSearchScope;9import java.util.Arrays;10import java.util.List;11import java.util.Optional;12import java.util.stream.Collectors;13import static com.intellij.openapi.actionSystem.CommonDataKeys.PSI_ELEMENT;14public class ReplaceCategoryAction extends AnAction {15 private Project project;16 @Override17 public void actionPerformed(AnActionEvent e) {18 project = e.getProject();19 PsiElement psiElement = e.getData(PSI_ELEMENT);20 if (psiElement instanceof PsiClass) {21 replaceCategory((PsiClass) psiElement);22 }23 }24 private void replaceCategory(PsiClass psiClass) {25 Arrays.stream(psiClass.getMethods())26 .filter(m -> hasAnnotation(m, "org.junit.Test"))27 .filter(m -> hasAnnotation(m, "org.junit.experimental.categories.Category"))28 .forEach(this::replaceCategory);29 }30 private void replaceCategory(PsiMethod psiMethod) {31 PsiAnnotation name =32 psiMethod.getModifierList()33 .findAnnotation("org.junit.experimental.categories.Category");34 String value = name.35 findDeclaredAttributeValue("value").getText();36 List<String> techCategories = getTechCategories(value);37 String productCategory = getProductCategory(value);38 addFeature(psiMethod, productCategory);39 addTypes(psiMethod, techCategories);40 deleteCategory(psiMethod);41 }42 private void deleteCategory(PsiMethod psiMethod) {43 PsiAnnotation oldFeature =44 psiMethod.getModifierList()45 .findAnnotation("org.junit.experimental.categories.Category");46 CommandProcessor.getInstance().executeCommand(project, () ->47 ApplicationManager.getApplication().runWriteAction(() -> {48 oldFeature.delete();49 }), null, null);50 }51 private void addTypes(PsiMethod psiMethod, List<String> techCategories) {52 String text = getTypesAnnotation(techCategories);53 CommandProcessor.getInstance().executeCommand(project, () ->54 ApplicationManager.getApplication().runWriteAction(() -> {55 PsiAnnotation ann = createAnnotation(text, psiMethod);56 addAfterTest(ann, psiMethod);57 addImport(psiMethod.getContainingFile(), "com.wrike.annotation.Types");58 addImport(psiMethod.getContainingFile(), "com.wrike.annotation.Type");59 JavaCodeStyleManager.getInstance(project).shortenClassReferences(ann);60 }), null, null);61 }62 private void addAfterTest(PsiAnnotation psiAnnotation, PsiMethod psiMethod) {63 PsiAnnotation test = psiMethod.getModifierList().findAnnotation("org.junit.Test");64 psiMethod.getModifierList().addAfter(psiAnnotation, test);65 }66 private PsiAnnotation createAnnotation(String text, PsiMethod psiMethod) {67 return JavaPsiFacade.getInstance(project).getElementFactory().createAnnotationFromText(text, psiMethod);68 }69 private String getInnerType(List<String> feature) {70 return "{" + feature.stream().map(s -> "@Type(\"" + s + "\")").collect(Collectors.joining(",")) + "}";71 }72 private String getTypesAnnotation(List<String> feature) {73 String inner = getInnerType(feature);74 return "@Types(" + inner + ")";75 }76 private void addFeature(PsiMethod psiMethod, String productCategory) {77 String text = "io.qameta.allure.Feature(\"" + productCategory + "\")";78 CommandProcessor.getInstance().executeCommand(project, () ->79 ApplicationManager.getApplication().runWriteAction(() -> {80 PsiAnnotation ann = psiMethod.getModifierList().addAnnotation(text);81 JavaCodeStyleManager.getInstance(project).shortenClassReferences(ann);82 }), null, null);83 }84 private List<String> getTechCategories(String category) {85 List<String> tech = Arrays.asList("Smoke", "Firefox");86 return Arrays.stream(category.substring(1, category.length() - 1)87 .split(", ")).map(s -> s.substring(0, s.indexOf('.')))88 .filter(tech::contains).collect(Collectors.toList());89 }90 private String getProductCategory(String category) {91 List<String> prod = Arrays.asList("Login");92 return Arrays.stream(category.substring(1, category.length() - 1)93 .split(", "))94 .map(s -> s.substring(0, s.indexOf('.')))95 .filter(prod::contains).findFirst().get();96 }97 private boolean hasAnnotation(PsiMethod psiMethod, String annotationQualifiedName) {98 return Arrays.stream(psiMethod.getAnnotations())99 .anyMatch(psiAnnotation -> psiAnnotation.getQualifiedName().contains(annotationQualifiedName));100 }101 private void addImport(final PsiFile file, final String qualifiedName) {102 if (file instanceof PsiJavaFile) {103 addImport((PsiJavaFile) file, qualifiedName);104 }105 }106 private void addImport(final PsiJavaFile file, final String qualifiedName) {107 final Project project = file.getProject();108 Optional<PsiClass> possibleClass = Optional.ofNullable(JavaPsiFacade.getInstance(project)109 .findClass(qualifiedName, GlobalSearchScope.everythingScope(project)));110 possibleClass.ifPresent(psiClass -> JavaCodeStyleManager.getInstance(project).addImport(file, psiClass));111 }112}...

Full Screen

Full Screen

Source:ClassPathScanSuite.java Github

copy

Full Screen

1package firebats.test.junit;23import java.io.IOException;4import java.lang.annotation.ElementType;5import java.lang.annotation.Inherited;6import java.lang.annotation.Retention;7import java.lang.annotation.RetentionPolicy;8import java.lang.annotation.Target;910import javax.annotation.Nullable;1112import org.junit.experimental.categories.Categories.CategoryFilter;13import org.junit.experimental.categories.Categories.ExcludeCategory;14import org.junit.experimental.categories.Categories.IncludeCategory;15import org.junit.runner.Description;16import org.junit.runner.manipulation.Filter;17import org.junit.runner.manipulation.NoTestsRemainException;18import org.junit.runners.model.InitializationError;19import org.junit.runners.model.RunnerBuilder;2021import com.google.common.base.Function;22import com.google.common.base.Predicate;23import com.google.common.collect.FluentIterable;24import com.google.common.collect.ImmutableSet;25import com.google.common.collect.Iterables;26import com.google.common.reflect.ClassPath;27import com.google.common.reflect.ClassPath.ClassInfo;2829/**30 * 自动classpath查找Suite实现31 * 32 * 范例:33 * @RunWith(ClassPathSuite.class)34 * @IncludeCategory(SlowTestCategory.class)35 * @SuiteClasses(packageName="junit4")36 * public class AllSlowTests {37 * }38 * 39 * public interface SlowTestCategory {}40 * 41 * @Category(SlowTestCategory.class)42 * public class ASlowTest {43 * @Test public void test() {}44 * }45 */46public class ClassPathScanSuite extends org.junit.runners.Suite {47 /**48 * The <code>SuiteClasses</code> annotation specifies the classes to be run when a class49 * annotated with <code>@RunWith(Suite.class)</code> is run.50 */51 @Retention(RetentionPolicy.RUNTIME)52 @Target(ElementType.TYPE)53 @Inherited54 public @interface SuiteClasses {55 /**56 * @return the classes to be run57 */58 public String packageName();59 }6061 static public ClassPath classpath;62 static {63 try {64 classpath = ClassPath.from(Thread.currentThread().getContextClassLoader());65 } catch (IOException e) {66 throw new RuntimeException(e);67 }68 }697071 /**72 * for junit invoke.73 */74 public ClassPathScanSuite(Class<?> clazz, RunnerBuilder builder)75 throws InitializationError {76 super(builder, clazz, Iterables.toArray(getClasses(getPackageName(clazz), getIncludedCategory(clazz)), Class.class));77 CategoryFilter filter=new CategoryFilter(getIncludedCategory(clazz),getExcludedCategory(clazz));78 try {79 filter(new ClassPathCategoryFilter(getPackageName(clazz),filter));80 } catch (NoTestsRemainException e) {81 throw new InitializationError(e);82 }83 }84 85 public static class ClassPathCategoryFilter extends Filter {86 private String packageName;87 CategoryFilter filter;88 public ClassPathCategoryFilter(String packageName,CategoryFilter filter) {89 this.filter=filter;90 this.packageName=packageName;91 }92 @Override93 public boolean shouldRun(Description description) {94 if(description!=null&&description.getTestClass()!=null){95 return description.getTestClass().getPackage().getName().startsWith(packageName)96 &&filter.shouldRun(description);97 }98 return false;99 }100 @Override101 public String describe() { 102 return filter.describe() +" ,packages " +packageName;103 }104 }105106 private static ImmutableSet<Class<?>> getClasses(String packageName,107 final Class<?> annotationClass) {108 return FluentIterable109 .from(classpath.getTopLevelClassesRecursive(packageName))110 .filter(new Predicate<ClassPath.ClassInfo>() {111 @Override112 public boolean apply(ClassInfo input) {113 return true;114 }115 })116 .transform(new Function<ClassInfo, Class<?>>() {117 @Override118 @Nullable119 public Class<?> apply(@Nullable ClassInfo input) {120 try {121 return Class.forName(input.getName());122 } catch (ClassNotFoundException e) {123 throw new RuntimeException(e);124 }125 }126 })127 .filter(new Predicate<Class<?>>() {128 @Override129 public boolean apply(@Nullable Class<?> input) {130 return true;131 }132 }).toSet();133 }134 135 private static Class<?> getExcludedCategory(Class<?> klass) {136 ExcludeCategory annotation= klass.getAnnotation(ExcludeCategory.class);137 return annotation == null ? null : annotation.value();138 }139 private static Class<?> getIncludedCategory(Class<?> klass) {140 IncludeCategory annotation= klass.getAnnotation(IncludeCategory.class);141 return annotation == null ? null : annotation.value();142 }143 private static String getPackageName(Class<?> klass) {144 SuiteClasses annotation= klass.getAnnotation(SuiteClasses.class);145 return annotation == null ? "no package name" : annotation.packageName();146 }147} ...

Full Screen

Full Screen

Source:CategoryValidator.java Github

copy

Full Screen

1/* */ package org.junit.experimental.categories;2/* */ 3/* */ import java.lang.annotation.Annotation;4/* */ import java.util.ArrayList;5/* */ import java.util.Arrays;6/* */ import java.util.Collections;7/* */ import java.util.HashSet;8/* */ import java.util.List;9/* */ import java.util.Set;10/* */ import org.junit.After;11/* */ import org.junit.AfterClass;12/* */ import org.junit.Before;13/* */ import org.junit.BeforeClass;14/* */ import org.junit.runners.model.FrameworkMethod;15/* */ import org.junit.validator.AnnotationValidator;16/* */ 17/* */ 18/* */ 19/* */ 20/* */ 21/* */ 22/* */ 23/* */ 24/* */ 25/* */ 26/* */ 27/* */ public final class CategoryValidator28/* */ extends AnnotationValidator29/* */ {30/* 30 */ private static final Set<Class<? extends Annotation>> INCOMPATIBLE_ANNOTATIONS = Collections.unmodifiableSet(new HashSet<Class<? extends Annotation>>(Arrays.asList((Class<? extends Annotation>[])new Class[] { BeforeClass.class, AfterClass.class, Before.class, After.class })));31/* */ 32/* */ 33/* */ 34/* */ 35/* */ 36/* */ 37/* */ 38/* */ 39/* */ 40/* */ 41/* */ 42/* */ 43/* */ 44/* */ public List<Exception> validateAnnotatedMethod(FrameworkMethod method) {45/* 45 */ List<Exception> errors = new ArrayList<Exception>();46/* 46 */ Annotation[] annotations = method.getAnnotations();47/* 47 */ for (Annotation annotation : annotations) {48/* 48 */ for (Class<?> clazz : INCOMPATIBLE_ANNOTATIONS) {49/* 49 */ if (annotation.annotationType().isAssignableFrom(clazz)) {50/* 50 */ addErrorMessage(errors, clazz);51/* */ }52/* */ } 53/* */ } 54/* 54 */ return Collections.unmodifiableList(errors);55/* */ }56/* */ 57/* */ private void addErrorMessage(List<Exception> errors, Class<?> clazz) {58/* 58 */ String message = String.format("@%s can not be combined with @Category", new Object[] { clazz.getSimpleName() });59/* */ 60/* 60 */ errors.add(new Exception(message));61/* */ }62/* */ }63/* Location: C:\Users\CAR\Desktop\sab\SAB_projekat_1920\SAB_projekat_1920\SAB_projekat_1920.jar!\org\junit\experimental\categories\CategoryValidator.class64 * Java compiler version: 5 (49.0)65 * JD-Core Version: 1.1.366 */...

Full Screen

Full Screen

Source:IntegrationTestData.java Github

copy

Full Screen

1package com.mass3d;2import java.lang.annotation.ElementType;3import java.lang.annotation.Retention;4import java.lang.annotation.RetentionPolicy;5import java.lang.annotation.Target;6/**7 * This annotation is used within a Docker-based integration test to inject data into the8 * Dockerized Postgresql database.9 * The annotation expects a "path" property to point to the actual SQL file containing the INSERT/UPDATE/DELETE10 * statements to run prior to each test. The file must be present in the classpath (e.g. src/main/resources/)11 * The data file is going to be injected only once per each test class.12 *13 * <pre>{@code14 *15 * @org.junit.experimental.categories.Category( IntegrationTest.class )16 * @IntegrationTestData(path = "sql/mydata.sql")17 * public class DefaultTrackedEntityInstanceStoreTest18 * extends19 * IntegrationTestBase20 * {21 * ...22 * }23 * }</pre>24 *25 *26 */27@Retention( RetentionPolicy.RUNTIME )28@Target( ElementType.TYPE )29public @interface IntegrationTestData30{31 String path();32}...

Full Screen

Full Screen

Source:Annotation.java Github

copy

Full Screen

1package org.apache.beam.sdk.testing;2import java.lang.annotation.Annotation;3import java.util.Arrays;4import org.apache.beam.vendor.guava.v20_0.com.google.common.base.Predicate;5import org.apache.beam.vendor.guava.v20_0.com.google.common.collect.FluentIterable;6import org.junit.experimental.categories.Category;7/** A utility class for querying annotations. */8class Annotations {9 /** Annotation predicates. */10 static class Predicates {11 static Predicate<Annotation> isAnnotationOfType(final Class<? extends Annotation> clazz) {12 return annotation ->13 annotation.annotationType() != null && annotation.annotationType().equals(clazz);14 }15 static Predicate<Annotation> isCategoryOf(final Class<?> value, final boolean allowDerived) {16 return category ->17 FluentIterable.from(Arrays.asList(((Category) category).value()))18 .anyMatch(19 aClass -> allowDerived ? value.isAssignableFrom(aClass) : value.equals(aClass));20 }21 }22}...

Full Screen

Full Screen

Source:WipTest.java Github

copy

Full Screen

1package pl.edc.dc;2import org.junit.experimental.categories.Category;3import java.lang.annotation.Retention;4import java.lang.annotation.RetentionPolicy;5import java.lang.annotation.Target;6import static java.lang.annotation.ElementType.METHOD;7import static java.lang.annotation.ElementType.TYPE;8@Category(WipTest.class)9@Target({METHOD, TYPE})10@Retention(RetentionPolicy.RUNTIME)11public @interface WipTest {12}...

Full Screen

Full Screen

Annotation Type Category

Using AI Code Generation

copy

Full Screen

1import org.junit.experimental.categories.Categories;2import org.junit.experimental.categories.Category;3import org.junit.runner.RunWith;4import org.junit.runners.Suite;5import org.junit.runners.Suite.SuiteClasses;6@RunWith(Categories.class)7@Categories.IncludeCategory(RegressionTest.class)8@Categories.ExcludeCategory(SmokeTest.class)9@SuiteClasses({ TestClass1.class, TestClass2.class })10public class TestSuite {11}12import org.junit.Test;13import org.junit.experimental.categories.Category;14@Category({ RegressionTest.class, SmokeTest.class })15public class TestClass1 {16public void testMethod1() {17}18public void testMethod2() {19}20public void testMethod3() {21}22public void testMethod4() {23}24public void testMethod5() {25}26public void testMethod6() {27}28public void testMethod7() {29}30public void testMethod8() {31}32public void testMethod9() {33}34public void testMethod10() {35}36public void testMethod11() {37}38public void testMethod12() {39}40public void testMethod13() {41}42public void testMethod14() {43}44public void testMethod15() {45}46public void testMethod16() {47}48public void testMethod17() {49}50public void testMethod18() {51}52public void testMethod19() {53}54public void testMethod20() {55}56public void testMethod21() {57}58public void testMethod22() {59}60public void testMethod23() {61}62public void testMethod24() {63}64public void testMethod25() {65}66public void testMethod26() {67}68public void testMethod27() {69}70public void testMethod28() {71}72public void testMethod29() {73}74public void testMethod30() {75}76public void testMethod31() {77}78public void testMethod32() {79}80public void testMethod33() {81}82public void testMethod34() {83}84public void testMethod35() {85}86public void testMethod36() {87}88public void testMethod37() {89}90public void testMethod38() {91}

Full Screen

Full Screen

Annotation Type Category

Using AI Code Generation

copy

Full Screen

1import org.junit.experimental.categories.Category;2import org.junit.runner.RunWith;3import org.junit.runners.Suite;4import org.junit.runners.Suite.SuiteClasses;5@RunWith(Suite.class)6@SuiteClasses({TestSuite.class})7public class TestSuite {8}9import org.junit.experimental.categories.Category;10@Category(CategoryA.class)11public class TestA {12}13import org.junit.experimental.categories.Category;14@Category(CategoryB.class)15public class TestB {16}17import org.junit.experimental.categories.Category;18@Category(CategoryA.class)19public class TestC {20}21import org.junit.experimental.categories.Category;22@Category(CategoryA.class)23public class TestD {24}25import org.junit.experimental.categories.Category;26@Category(CategoryB.class)27public class TestE {28}29import org.junit.experimental.categories.Category;30@Category(CategoryB.class)31public class TestF {32}33import org.junit.experimental.categories.Category;34@Category(CategoryA.class)35public class TestG {36}37import org.junit.experimental.categories.Category;38@Category(CategoryA.class)39public class TestH {40}41import org.junit.experimental.categories.Category;42@Category(CategoryB.class)43public class TestI {44}45import org.junit.experimental.categories.Category;46@Category(CategoryB.class)47public class TestJ {48}49import org.junit.experimental.categories.Category;50@Category(CategoryA.class)51public class TestK {52}53import org.junit.experimental.categories.Category;54@Category(CategoryA.class)55public class TestL {56}57import org.junit.experimental.categories.Category;58@Category(CategoryB.class)59public class TestM {60}61import org.junit.experimental.categories.Category;62@Category(CategoryB.class)63public class TestN {64}65import org.junit.experimental.categories.Category;66@Category(CategoryA.class)67public class TestO {68}69import org.junit.experimental.categories.Category;70@Category(CategoryA.class)71public class TestP {72}73import org.junit.experimental.categories.Category;74@Category(CategoryB.class)75public class TestQ {76}77import org.junit.experimental.categories.Category;78@Category(CategoryB.class)79public class TestR {80}81import org.junit.experimental.categories.Category;82@Category(CategoryA.class)83public class TestS {84}85import org.junit.experimental.categories.Category;

Full Screen

Full Screen

Annotation Type Category

Using AI Code Generation

copy

Full Screen

1import org.junit.experimental.categories.Category;2import org.junit.runner.RunWith;3import org.junit.runners.Suite;4import org.junit.runners.Suite.SuiteClasses;5@RunWith(Suite.class)6@SuiteClasses({ CategoryA.class, CategoryB.class })7public class TestSuiteCategory {8}9package com.javacodegeeks.junit;10import org.junit.Test;11import org.junit.experimental.categories.Category;12public class CategoryA {13@Category(CategoryA.class)14public void testA() {15System.out.println("testA");16}17}18package com.javacodegeeks.junit;19import org.junit.Test;20import org.junit.experimental.categories.Category;21public class CategoryB {22@Category(CategoryB.class)23public void testB() {24System.out.println("testB");25}26}27package com.javacodegeeks.junit;28import org.junit.Test;29import org.junit.experimental.categories.Category;30public class CategoryTest {31@Category(CategoryA.class)32public void testA() {33System.out.println("testA");34}35@Category(CategoryB.class)36public void testB() {37System.out.println("testB");38}39public void testC() {40System.out.println("testC");41}42}43package com.javacodegeeks.junit;44public interface CategoryA {45}46package com.javacodegeeks.junit;47public interface CategoryB {48}49package com.javacodegeeks.junit;50public interface CategoryA {51}52package com.javacodegeeks.junit;53public interface CategoryB {54}55package com.javacodegeeks.junit;56public interface CategoryA {57}58package com.javacodegeeks.junit;59public interface CategoryB {60}61package com.javacodegeeks.junit;62public interface CategoryA {63}64package com.javacodegeeks.junit;65public interface CategoryB {66}67package com.javacodegeeks.junit;68public interface CategoryA {69}70package com.javacodegeeks.junit;71public interface CategoryB {72}73package com.javacodegeeks.junit;74public interface CategoryA {75}76package com.javacodegeeks.junit;77public interface CategoryB {78}

Full Screen

Full Screen

Annotation Type Category

Using AI Code Generation

copy

Full Screen

1import org.junit.experimental.categories.Category;2public class TestClass1 {3 @Category(SmokeTests.class)4 public void test1() {5 System.out.println("Test 1");6 }7 @Category(SmokeTests.class)8 public void test2() {9 System.out.println("Test 2");10 }11 @Category(FullTests.class)12 public void test3() {13 System.out.println("Test 3");14 }15 @Category(FullTests.class)16 public void test4() {17 System.out.println("Test 4");18 }19}20import org.junit.experimental.categories.Category;21public class TestClass2 {22 @Category(SmokeTests.class)23 public void test1() {24 System.out.println("Test 1");25 }26 @Category(SmokeTests.class)27 public void test2() {28 System.out.println("Test 2");29 }30 @Category(FullTests.class)31 public void test3() {32 System.out.println("Test 3");33 }34 @Category(FullTests.class)35 public void test4() {36 System.out.println("Test 4");37 }38}39import org.junit.experimental.categories.Category;40public class TestClass3 {41 @Category(SmokeTests.class)42 public void test1() {43 System.out.println("Test 1");44 }45 @Category(SmokeTests.class)46 public void test2() {47 System.out.println("Test 2");48 }49 @Category(FullTests.class)50 public void test3() {51 System.out.println("Test 3");52 }53 @Category(FullTests.class)54 public void test4() {55 System.out.println("Test 4");56 }57}58import org.junit.experimental.categories.Category;59public class TestClass4 {60 @Category(SmokeTests.class)61 public void test1() {62 System.out.println("Test 1");63 }

Full Screen

Full Screen

Annotation Type Category

Using AI Code Generation

copy

Full Screen

1 @Category({TestGroup1.class, TestGroup2.class})2 public class TestClass2 {3 public void testMethod1() {4 System.out.println("Test method 1");5 }6 public void testMethod2() {7 System.out.println("Test method 2");8 }9 }10 @Category(TestGroup1.class)11 public class TestClass3 {12 public void testMethod1() {13 System.out.println("Test method 1");14 }15 public void testMethod2() {16 System.out.println("Test method 2");17 }18 }19 @Category(TestGroup2.class)20 public class TestClass4 {21 public void testMethod1() {22 System.out.println("Test method 1");23 }24 public void testMethod2() {25 System.out.println("Test method 2");26 }27 }28 @Category(TestGroup1.class)29 public class TestClass5 {30 public void testMethod1() {31 System.out.println("Test method 1");32 }33 public void testMethod2() {34 System.out.println("Test method 2");35 }36 }37 @Category(TestGroup2.class)38 public class TestClass6 {39 public void testMethod1() {40 System.out.println("Test method 1");41 }42 public void testMethod2() {43 System.out.println("Test method 2");44 }45 }46 @Category(TestGroup1.class)47 public class TestClass7 {48 public void testMethod1() {49 System.out.println("Test method 1");50 }51 public void testMethod2() {52 System.out.println("Test method 2");53 }54 }55 @Category(TestGroup2.class)

Full Screen

Full Screen
copy
1import org.mockito.Mock;2...3@Mock4MyService myservice;5
Full Screen

JUnit Tutorial:

LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.

JUnit Tutorial Chapters:

Here are the detailed JUnit testing chapters to help you get started:

  • Importance of Unit testing - Learn why Unit testing is essential during the development phase to identify bugs and errors.
  • Top Java Unit testing frameworks - Here are the upcoming JUnit automation testing frameworks that you can use in 2023 to boost your unit testing.
  • What is the JUnit framework
  • Why is JUnit testing important - Learn the importance and numerous benefits of using the JUnit testing framework.
  • Features of JUnit - Learn about the numerous features of JUnit and why developers prefer it.
  • JUnit 5 vs. JUnit 4: Differences - Here is a complete comparison between JUnit 5 and JUnit 4 testing frameworks.
  • Setting up the JUnit environment - Learn how to set up your JUnit testing environment.
  • Getting started with JUnit testing - After successfully setting up your JUnit environment, this chapter will help you get started with JUnit testing in no time.
  • Parallel testing with JUnit - Parallel Testing can be used to reduce test execution time and improve test efficiency. Learn how to perform parallel testing with JUnit.
  • Annotations in JUnit - When writing automation scripts with JUnit, we can use JUnit annotations to specify the type of methods in our test code. This helps us identify those methods when we run JUnit tests using Selenium WebDriver. Learn in detail what annotations are in JUnit.
  • Assertions in JUnit - Assertions are used to validate or test that the result of an action/functionality is the same as expected. Learn in detail what assertions are and how to use them while performing JUnit testing.
  • Parameterization in JUnit - Parameterized Test enables you to run the same automated test scripts with different variables. By collecting data on each method's test parameters, you can minimize time spent on writing tests. Learn how to use parameterization in JUnit.
  • Nested Tests In JUnit 5 - A nested class is a non-static class contained within another class in a hierarchical structure. It can share the state and setup of the outer class. Learn about nested annotations in JUnit 5 with examples.
  • Best practices for JUnit testing - Learn about the best practices, such as always testing key methods and classes, integrating JUnit tests with your build, and more to get the best possible results.
  • Advanced Use Cases for JUnit testing - Take a deep dive into the advanced use cases, such as how to run JUnit tests in Jupiter, how to use JUnit 5 Mockito for Unit testing, and more for JUnit testing.

JUnit Certification:

You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

...Most popular Stackoverflow questions on Annotation-Type-Category

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful