Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: test/com/google/gwt/inject/rebind/binding/BindConstantBindingTest.java

Issue 90085: Fixed enum binding support (issue #49) (Closed) SVN Base: http://google-gin.googlecode.com/svn/trunk/
Patch Set: Using getEnclosingClass Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2008 Google Inc. 2 * Copyright 2008 Google Inc.
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of 5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at 6 * the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.0 8 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software 10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under 13 * License for the specific language governing permissions and limitations under
14 * the License. 14 * the License.
15 */ 15 */
16 package com.google.gwt.inject.rebind.binding; 16 package com.google.gwt.inject.rebind.binding;
17 17
18 import com.google.gwt.inject.rebind.util.NameGenerator;
18 import com.google.gwt.inject.rebind.util.SourceWriteUtil; 19 import com.google.gwt.inject.rebind.util.SourceWriteUtil;
19 import com.google.gwt.user.rebind.SourceWriter; 20 import com.google.gwt.user.rebind.SourceWriter;
20 import com.google.inject.Key; 21 import com.google.inject.Key;
21 22
22 import junit.framework.TestCase; 23 import junit.framework.TestCase;
23 24
24 import static org.easymock.classextension.EasyMock.createMock; 25 import static org.easymock.classextension.EasyMock.createMock;
25 import static org.easymock.classextension.EasyMock.replay; 26 import static org.easymock.classextension.EasyMock.replay;
26 import static org.easymock.classextension.EasyMock.verify; 27 import static org.easymock.classextension.EasyMock.verify;
27 28
28 public class BindConstantBindingTest extends TestCase { 29 public class BindConstantBindingTest extends TestCase {
29 30
30 // TODO(schmitt): Add tests for other constant types. 31 // TODO(schmitt): Add tests for other constant types.
31 32
32 public void testEnum() { 33 public void testEnum() {
33 Key<Color> colorKey = Key.get(Color.class); 34 Key<Color> colorKey = Key.get(Color.class);
34 SourceWriteUtil utilMock = createMock(SourceWriteUtil.class); 35 SourceWriteUtil utilMock = createMock(SourceWriteUtil.class);
35 SourceWriter writerMock = createMock(SourceWriter.class); 36 SourceWriter writerMock = createMock(SourceWriter.class);
36 37
37 String signature = ""; 38 String signature = "";
38 utilMock.writeMethod(writerMock, signature, 39 utilMock.writeMethod(writerMock, signature,
39 "return com.google.gwt.inject.rebind.binding.Color.Green;"); 40 "return com.google.gwt.inject.rebind.binding.Color.Green;");
40 replay(utilMock); 41 replay(utilMock);
41 42
42 BindConstantBinding binding = new BindConstantBinding(utilMock); 43 BindConstantBinding binding = new BindConstantBinding(utilMock, new NameGene rator());
43 binding.setKeyAndInstance(colorKey, Color.Green); 44 binding.setKeyAndInstance(colorKey, Color.Green);
44 45
45 assertTrue(binding.getRequiredKeys().getRequiredKeys().isEmpty()); 46 assertTrue(binding.getRequiredKeys().getRequiredKeys().isEmpty());
46 47
47 binding.writeCreatorMethods(writerMock, signature); 48 binding.writeCreatorMethods(writerMock, signature);
48 49
50 verify(utilMock);
51 }
52
53 public void testInnerEnum() {
54 Key<Font> fontKey = Key.get(Font.class);
55 SourceWriteUtil utilMock = createMock(SourceWriteUtil.class);
56 SourceWriter writerMock = createMock(SourceWriter.class);
57
58 String signature = "";
59 utilMock.writeMethod(writerMock, signature,
60 "return com.google.gwt.inject.rebind.binding.BindConstantBindingTest.Fon t.Verdana;");
61 replay(utilMock);
62
63 BindConstantBinding binding = new BindConstantBinding(utilMock, new NameGene rator());
64 binding.setKeyAndInstance(fontKey, Font.Verdana);
65
66 binding.writeCreatorMethods(writerMock, signature);
67
68 verify(utilMock);
69 }
70
71 public void testInnerEnumWithCustomImplementation() {
72 Key<Font> fontKey = Key.get(Font.class);
73 SourceWriteUtil utilMock = createMock(SourceWriteUtil.class);
74 SourceWriter writerMock = createMock(SourceWriter.class);
75
76 String signature = "";
77 utilMock.writeMethod(writerMock, signature,
78 "return com.google.gwt.inject.rebind.binding.BindConstantBindingTest.Fon t.Arial;");
79 replay(utilMock);
80
81 BindConstantBinding binding = new BindConstantBinding(utilMock, new NameGene rator());
82 binding.setKeyAndInstance(fontKey, Font.Arial);
83
84 binding.writeCreatorMethods(writerMock, signature);
85
49 verify(utilMock); 86 verify(utilMock);
50 } 87 }
51 88
52 public void testCharacter() { 89 public void testCharacter() {
53 Key<Character> charKey = Key.get(Character.class); 90 Key<Character> charKey = Key.get(Character.class);
54 SourceWriteUtil utilMock = createMock(SourceWriteUtil.class); 91 SourceWriteUtil utilMock = createMock(SourceWriteUtil.class);
55 SourceWriter writerMock = createMock(SourceWriter.class); 92 SourceWriter writerMock = createMock(SourceWriter.class);
56 93
57 char value = '\u1234'; 94 char value = '\u1234';
58 String signature = ""; 95 String signature = "";
59 96
60 utilMock.writeMethod(writerMock, signature, "return '" + value + "';"); 97 utilMock.writeMethod(writerMock, signature, "return '" + value + "';");
61 replay(utilMock); 98 replay(utilMock);
62 99
63 BindConstantBinding binding = new BindConstantBinding(utilMock); 100 BindConstantBinding binding = new BindConstantBinding(utilMock, new NameGene rator());
64 binding.setKeyAndInstance(charKey, value); 101 binding.setKeyAndInstance(charKey, value);
65 102
66 assertTrue(binding.getRequiredKeys().getRequiredKeys().isEmpty()); 103 assertTrue(binding.getRequiredKeys().getRequiredKeys().isEmpty());
67 104
68 binding.writeCreatorMethods(writerMock, signature); 105 binding.writeCreatorMethods(writerMock, signature);
69 106
70 verify(utilMock); 107 verify(utilMock);
71 } 108 }
72 109
73 public void testCharacterEscaped() { 110 public void testCharacterEscaped() {
74 Key<Character> charKey = Key.get(Character.class); 111 Key<Character> charKey = Key.get(Character.class);
75 SourceWriteUtil utilMock = createMock(SourceWriteUtil.class); 112 SourceWriteUtil utilMock = createMock(SourceWriteUtil.class);
76 SourceWriter writerMock = createMock(SourceWriter.class); 113 SourceWriter writerMock = createMock(SourceWriter.class);
77 114
78 char value = '\''; 115 char value = '\'';
79 String signature = ""; 116 String signature = "";
80 117
81 utilMock.writeMethod(writerMock, signature, "return '\\'';"); 118 utilMock.writeMethod(writerMock, signature, "return '\\'';");
82 replay(utilMock); 119 replay(utilMock);
83 120
84 BindConstantBinding binding = new BindConstantBinding(utilMock); 121 BindConstantBinding binding = new BindConstantBinding(utilMock, new NameGene rator());
85 binding.setKeyAndInstance(charKey, value); 122 binding.setKeyAndInstance(charKey, value);
86 123
87 assertTrue(binding.getRequiredKeys().getRequiredKeys().isEmpty()); 124 assertTrue(binding.getRequiredKeys().getRequiredKeys().isEmpty());
88 125
89 binding.writeCreatorMethods(writerMock, signature); 126 binding.writeCreatorMethods(writerMock, signature);
90 127
91 verify(utilMock); 128 verify(utilMock);
92 } 129 }
130
131 public enum Font {
132 Arial {
133
134 @Override public Font getAlternative() {
135 return Verdana;
136 }},
137 Verdana,
138 TimesNewRoman;
139
140 public Font getAlternative() {
141 return this;
142 }
143 }
93 } 144 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497