1+ package com .flit .protoc ;
2+
3+ import com .google .protobuf .compiler .PluginProtos ;
4+ import org .junit .Test ;
5+
6+ import static junit .framework .TestCase .assertTrue ;
7+ import static org .junit .Assert .assertEquals ;
8+ import static org .junit .Assert .assertFalse ;
9+
10+ public class PluginTest {
11+
12+ @ Test
13+ public void test_NoParameters () {
14+ Plugin plugin = new Plugin (PluginProtos .CodeGeneratorRequest .newBuilder ().build ());
15+ PluginProtos .CodeGeneratorResponse response = plugin .process ();
16+
17+ assertTrue ("Expected an error for no parameters" , response .hasError ());
18+ assertEquals (
19+ "Incorrect error message" ,
20+ "Usage: --flit_out=target=server,type=[spring]:<PATH>" ,
21+ response .getError ()
22+ );
23+ }
24+
25+ @ Test
26+ public void test_NoTargetSpecified () {
27+ Plugin plugin = new Plugin (PluginProtos .CodeGeneratorRequest .newBuilder ().setParameter ("unknown=unknown" ).build ());
28+ PluginProtos .CodeGeneratorResponse response = plugin .process ();
29+
30+ assertTrue ("Expected an error for unknown target type" , response .hasError ());
31+ assertEquals (
32+ "Incorrect error message" ,
33+ "No argument specified for target" ,
34+ response .getError ()
35+ );
36+ }
37+
38+ @ Test
39+ public void test_UnknownTargetType () {
40+ Plugin plugin = new Plugin (PluginProtos .CodeGeneratorRequest .newBuilder ().setParameter ("target=unknown,type=boot" ).build ());
41+ PluginProtos .CodeGeneratorResponse response = plugin .process ();
42+
43+ assertTrue ("Expected an error for unknown target type" , response .hasError ());
44+ assertEquals (
45+ "Incorrect error message" ,
46+ "Unknown target type: unknown" ,
47+ response .getError ()
48+ );
49+ }
50+
51+ @ Test
52+ public void test_EmptyTargetType () {
53+ Plugin plugin = new Plugin (PluginProtos .CodeGeneratorRequest .newBuilder ().setParameter ("target=" ).build ());
54+ PluginProtos .CodeGeneratorResponse response = plugin .process ();
55+
56+ assertTrue ("Expected an error for unknown target type" , response .hasError ());
57+ assertEquals (
58+ "Incorrect error message" ,
59+ "No argument specified for target" ,
60+ response .getError ()
61+ );
62+ }
63+
64+ @ Test
65+ public void test_MissingTargetType () {
66+ Plugin plugin = new Plugin (PluginProtos .CodeGeneratorRequest .newBuilder ().setParameter ("target=server" ).build ());
67+ PluginProtos .CodeGeneratorResponse response = plugin .process ();
68+
69+ assertTrue ("Expected an error for unknown server type" , response .hasError ());
70+ assertEquals (
71+ "Incorrect error message" ,
72+ "No argument specified for type" ,
73+ response .getError ()
74+ );
75+ }
76+
77+ @ Test
78+ public void test_UnknownServerType () {
79+ Plugin plugin = new Plugin (PluginProtos .CodeGeneratorRequest .newBuilder ().setParameter ("target=server,type=unknown" ).build ());
80+ PluginProtos .CodeGeneratorResponse response = plugin .process ();
81+
82+ assertTrue ("Expected an error for unknown server type" , response .hasError ());
83+ assertEquals (
84+ "Incorrect error message" ,
85+ "Unknown server type: unknown" ,
86+ response .getError ()
87+ );
88+ }
89+
90+ @ Test
91+ public void test_MissingServerType () {
92+ Plugin plugin = new Plugin (PluginProtos .CodeGeneratorRequest .newBuilder ().setParameter ("target=server,type=" ).build ());
93+ PluginProtos .CodeGeneratorResponse response = plugin .process ();
94+
95+ assertTrue ("Expected an error for unknown server type" , response .hasError ());
96+ assertEquals (
97+ "Incorrect error message" ,
98+ "No argument specified for type" ,
99+ response .getError ()
100+ );
101+ }
102+
103+ @ Test
104+ public void test_EmptyProtoList () {
105+ Plugin plugin = new Plugin (PluginProtos .CodeGeneratorRequest .newBuilder ().setParameter ("target=server,type=boot" ).build ());
106+ PluginProtos .CodeGeneratorResponse response = plugin .process ();
107+
108+ assertFalse ("No error expected for empty file list" , response .hasError ());
109+ assertEquals ("Expected no files generated" , 0 , response .getFileCount ());
110+ }
111+
112+ }
0 commit comments