You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UIProviderTest.java 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package com.vaadin.server;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertNotNull;
  4. import java.lang.annotation.ElementType;
  5. import java.lang.annotation.Retention;
  6. import java.lang.annotation.RetentionPolicy;
  7. import java.lang.annotation.Target;
  8. import org.junit.Test;
  9. import com.vaadin.annotations.Theme;
  10. import com.vaadin.annotations.Widgetset;
  11. /**
  12. * Tests for {@link UIProvider} class.
  13. *
  14. * @author Vaadin Ltd
  15. */
  16. public class UIProviderTest {
  17. @Test
  18. public void getAnnotationFor_widgetsetAnnotationForSubclass_annotationFound() {
  19. assertNotNull("Widgetset annotation is not found for subclass",
  20. UIProvider.getAnnotationFor(TestClass.class, Widgetset.class));
  21. }
  22. @Test
  23. public void getAnnotationFor_themeAnnotationForSubclass_annotationFound() {
  24. assertNotNull("Theme annotation is not found for subclass",
  25. UIProvider.getAnnotationFor(TestClass.class, Theme.class));
  26. }
  27. @Test
  28. public void getAnnotationFor_themeAnnotationForSubclass_annotationOverridden() {
  29. assertEquals("Theme annotation is not overridden correctly in subclass",
  30. "c", UIProvider.getAnnotationFor(TestClass.class, Theme.class)
  31. .value());
  32. }
  33. @Test
  34. public void getAnnotationFor_notInheritedAnnotationForSubclass_annotationFound() {
  35. assertNotNull("TestAnnotation annotation is not found for subclass",
  36. UIProvider.getAnnotationFor(TestClass.class,
  37. TestAnnotation.class));
  38. }
  39. @Test
  40. public void getAnnotationFor_directAnnotationForSubclass_annotationFound() {
  41. assertNotNull("TestAnnotation1 annotation is not found for subclass",
  42. UIProvider.getAnnotationFor(TestClass.class,
  43. TestAnnotation1.class));
  44. }
  45. @Test
  46. public void getAnnotationFor_annotationInheritedFromInterface_annotationFound() {
  47. assertNotNull("Theme annotation is not inherited from interface",
  48. UIProvider.getAnnotationFor(ClassImplementingInterface.class,
  49. Theme.class));
  50. }
  51. @Retention(RetentionPolicy.RUNTIME)
  52. @Target(ElementType.TYPE)
  53. public @interface TestAnnotation {
  54. }
  55. @Retention(RetentionPolicy.RUNTIME)
  56. @Target(ElementType.TYPE)
  57. public @interface TestAnnotation1 {
  58. }
  59. @Widgetset("a")
  60. @Theme("b")
  61. @TestAnnotation
  62. public static class TestSuperClass {
  63. }
  64. @TestAnnotation1
  65. @Theme("c")
  66. public static class TestClass extends TestSuperClass {
  67. }
  68. @Theme("d")
  69. public interface InterfaceWithAnnotation {
  70. }
  71. public static class ClassImplementingInterface
  72. implements InterfaceWithAnnotation {
  73. }
  74. }