Skip to content

Commit deb6b1c

Browse files
thelsingadrienbaron
authored andcommitted
add test for default method
1 parent 26ebcac commit deb6b1c

File tree

6 files changed

+175
-0
lines changed

6 files changed

+175
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.axellience.vuegwt.processors.component.defaultmethods;
2+
3+
import com.axellience.vuegwt.processors.VueGwtProcessor;
4+
import com.google.testing.compile.Compilation;
5+
import com.google.testing.compile.JavaFileObjects;
6+
import org.junit.jupiter.api.DisplayName;
7+
import org.junit.jupiter.api.Test;
8+
9+
import static com.google.testing.compile.CompilationSubject.assertThat;
10+
import static com.google.testing.compile.Compiler.javac;
11+
12+
class DefaultMethodsBindingTest {
13+
14+
@Test
15+
@DisplayName("should bind component methods to default methods of interfaces of the option object")
16+
void bindComponentMethodsToOptions() {
17+
Compilation compilation =
18+
javac()
19+
.withProcessors(new VueGwtProcessor())
20+
.compile(
21+
JavaFileObjects.forResource("defaultmethods/DefaultMethodsComponent.java"));
22+
23+
assertThat(compilation)
24+
.generatedSourceFile("defaultmethods.DefaultMethodsComponentExposedType")
25+
.containsElementsIn(JavaFileObjects.forResource(
26+
"defaultmethods/compileresult/DefaultMethodsComponentExposedType.java"));
27+
}
28+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package common;
2+
3+
public interface InterfaceDefaultMethod {
4+
default String getDefaultText() {
5+
return "text";
6+
}
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package common;
2+
3+
public class SimpleObjectInterface implements InterfaceDefaultMethod {
4+
5+
String text;
6+
7+
public String getText() {
8+
return text;
9+
}
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
2+
<div>{{ simpleObject.getDefaultText() }}</div>
3+
<div>{{ simpleObject.getDefaultText() + " Expression 2" }}</div>
4+
<div @click="onClickMethod"></div>
5+
</div>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package defaultmethods;
2+
3+
import com.axellience.vuegwt.core.annotations.component.Component;
4+
import com.axellience.vuegwt.core.annotations.component.Data;
5+
import com.axellience.vuegwt.core.client.component.IsVueComponent;
6+
import com.axellience.vuegwt.core.client.component.hooks.HasCreated;
7+
import common.SimpleObjectInterface;
8+
import jsinterop.annotations.JsMethod;
9+
10+
@Component
11+
public class DefaultMethodsComponent implements IsVueComponent, HasCreated {
12+
13+
@Data
14+
SimpleObjectInterface simpleObject;
15+
16+
@JsMethod
17+
void onClickMethod() {
18+
19+
}
20+
21+
@Override
22+
public void created() {
23+
// Simple Hook
24+
}
25+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package defaultmethods;
2+
3+
import com.axellience.vuegwt.core.client.component.options.VueComponentOptions;
4+
import com.axellience.vuegwt.core.client.tools.FieldsExposer;
5+
import com.axellience.vuegwt.core.client.tools.VueGWTTools;
6+
import elemental2.core.Function;
7+
import java.lang.Object;
8+
import java.lang.String;
9+
import java.lang.SuppressWarnings;
10+
import javax.annotation.Generated;
11+
import jsinterop.annotations.JsMethod;
12+
import jsinterop.annotations.JsPackage;
13+
import jsinterop.annotations.JsProperty;
14+
import jsinterop.annotations.JsType;
15+
import jsinterop.base.Js;
16+
import jsinterop.base.JsPropertyMap;
17+
18+
@Generated(
19+
value = "com.axellience.vuegwt.processors.component.ComponentExposedTypeGenerator",
20+
comments = "https://github.com/Axellience/vue-gwt"
21+
)
22+
public class DefaultMethodsComponentExposedType extends DefaultMethodsComponent {
23+
@JsProperty
24+
public Proto __proto__;
25+
26+
@JsProperty
27+
public boolean vg$hrc_0;
28+
29+
@JsMethod
30+
public void vg$created() {
31+
if (vg$hrc_0) return;
32+
vg$hrc_0 = true;
33+
vue().$options().proxyFields(this);
34+
VueGWTTools.initComponentInstanceFields(this, new DefaultMethodsComponent());
35+
Proto p = Js.cast(vue().$options().getComponentExportedTypePrototype());
36+
super.created();
37+
}
38+
39+
public static String getScopedCss() {
40+
return null;
41+
}
42+
43+
private Function getRenderFunction() {
44+
String renderFunctionString = "with(this){return _c('div',[_c('div',[_v(_s(exp$0()))]),_v(\" \"),_c('div',[_v(_s(exp$1()))]),_v(\" \"),_c('div',{on:{\"click\":onClickMethod}})])}";
45+
return new Function(renderFunctionString);
46+
}
47+
48+
private Function[] getStaticRenderFunctions() {
49+
return new Function[] { };
50+
}
51+
52+
@JsMethod
53+
@SuppressWarnings("unusable-by-js")
54+
public String exp$0() {
55+
// DefaultMethodsComponent.html, line 2
56+
return VueGWTTools.templateExpressionToString(simpleObject.getDefaultText());
57+
}
58+
59+
@JsMethod
60+
@SuppressWarnings("unusable-by-js")
61+
public String exp$1() {
62+
// DefaultMethodsComponent.html, line 3
63+
return VueGWTTools.templateExpressionToString(simpleObject.getDefaultText() + " Expression 2");
64+
}
65+
66+
public VueComponentOptions<DefaultMethodsComponent> getOptions() {
67+
VueComponentOptions<DefaultMethodsComponent> options = new VueComponentOptions<DefaultMethodsComponent>();
68+
Proto p = __proto__;
69+
options.setComponentExportedTypePrototype(p);
70+
options.addMethod("onClickMethod", p.onClickMethod);
71+
options.addHookMethod("created", p.vg$created);
72+
options.initData(true, VueGWTTools.getFieldsName(this, () -> {
73+
this.simpleObject = null;
74+
} ));
75+
options.registerTemplateMethods(p.exp$0, p.exp$1);
76+
options.initRenderFunctions(getRenderFunction(), getStaticRenderFunctions());
77+
return options;
78+
}
79+
80+
@JsMethod
81+
void vg$ef() {
82+
this.simpleObject = FieldsExposer.v();
83+
FieldsExposer.e(simpleObject);
84+
}
85+
86+
@JsType(
87+
isNative = true,
88+
namespace = JsPackage.GLOBAL,
89+
name = "Object"
90+
)
91+
private static class Proto implements JsPropertyMap<Object> {
92+
public Function onClickMethod;
93+
94+
public Function vg$created;
95+
96+
public Function exp$0;
97+
98+
public Function exp$1;
99+
}
100+
}

0 commit comments

Comments
 (0)