1 package com.atlassian.pageobjects.util;
2
3 import com.atlassian.pageobjects.TestedProduct;
4 import com.atlassian.pageobjects.inject.ConfigurableInjectionContext;
5 import com.atlassian.pageobjects.inject.InjectionContext;
6
7
8
9
10
11
12 public final class InjectingTestedProducts
13 {
14
15 private InjectingTestedProducts()
16 {
17 throw new AssertionError("Don't instantiate me");
18 }
19
20
21
22
23
24
25
26
27
28 public static boolean supportsInjection(TestedProduct<?> product)
29 {
30 if (product == null)
31 {
32 return false;
33 }
34 return product instanceof InjectionContext || product.getPageBinder() instanceof InjectionContext;
35 }
36
37
38
39
40
41
42
43
44 public static boolean supportsConfigurableInjection(TestedProduct<?> product)
45 {
46 if (product == null)
47 {
48 return false;
49 }
50 return product instanceof ConfigurableInjectionContext || product.getPageBinder() instanceof ConfigurableInjectionContext;
51 }
52
53
54
55
56
57
58
59
60
61 public static InjectionContext asInjectionContext(TestedProduct<?> product)
62 {
63 if (product instanceof InjectionContext)
64 {
65 return (InjectionContext) product;
66 }
67 else if (product.getPageBinder() instanceof InjectionContext)
68 {
69 return (InjectionContext) product.getPageBinder();
70 }
71 else
72 {
73 throw new IllegalArgumentException("Product <" + product + "> does not support injection");
74 }
75 }
76
77
78
79
80
81
82
83
84
85
86 public static ConfigurableInjectionContext asConfigurableInjectionContext(TestedProduct<?> product)
87 {
88 if (product instanceof ConfigurableInjectionContext)
89 {
90 return (ConfigurableInjectionContext) product;
91 }
92 else if (product.getPageBinder() instanceof InjectionContext)
93 {
94 return (ConfigurableInjectionContext) product.getPageBinder();
95 }
96 else
97 {
98 throw new IllegalArgumentException("Product <" + product + "> does not support configurable injection");
99 }
100 }
101 }