Skip to content

Commit faa39c7

Browse files
lukesandbergsameb
authored andcommitted
Run google-java-format on all Guice code.
configure a presubmit to ensure that it stays formatted. Highlights include: * simplified import order * method annotations are now consistently defined on the preceding line * javadoc reformatted to 100 chars column width One test that contained line numbers in error messages had to be modified and the formatter didn't like some of the more complicated preprocessor directives (MOE and AOP). To avoid formatting the copyright notices as javadoc i did a preprocessing step to rewrite the initial '/**' to '/*' using perl ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=132688230
1 parent 37c7eba commit faa39c7

30 files changed

+1537
-1418
lines changed

extensions/servlet/test/com/google/inject/servlet/AllTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2008 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,9 +19,7 @@
1919
import junit.framework.Test;
2020
import junit.framework.TestSuite;
2121

22-
/**
23-
* @author [email protected] (Dhanji R. Prasanna)
24-
*/
22+
/** @author [email protected] (Dhanji R. Prasanna) */
2523
public class AllTests {
2624

2725
public static Test suite() {

extensions/servlet/test/com/google/inject/servlet/ContextPathTest.java

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2011 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,13 +26,7 @@
2626
import com.google.inject.Scopes;
2727
import com.google.inject.name.Named;
2828
import com.google.inject.name.Names;
29-
30-
import junit.framework.TestCase;
31-
32-
import org.easymock.IMocksControl;
33-
3429
import java.io.IOException;
35-
3630
import javax.servlet.FilterChain;
3731
import javax.servlet.FilterConfig;
3832
import javax.servlet.ServletContext;
@@ -42,14 +36,18 @@
4236
import javax.servlet.http.HttpServlet;
4337
import javax.servlet.http.HttpServletRequest;
4438
import javax.servlet.http.HttpServletResponse;
39+
import junit.framework.TestCase;
40+
import org.easymock.IMocksControl;
4541

4642
/** Tests to make sure that servlets with a context path are handled right. */
4743
public class ContextPathTest extends TestCase {
4844

49-
@Inject @Named("foo")
45+
@Inject
46+
@Named("foo")
5047
private TestServlet fooServlet;
5148

52-
@Inject @Named("bar")
49+
@Inject
50+
@Named("bar")
5351
private TestServlet barServlet;
5452

5553
private IMocksControl globalControl;
@@ -60,18 +58,24 @@ public class ContextPathTest extends TestCase {
6058

6159
@Override
6260
public final void setUp() throws Exception {
63-
injector = Guice.createInjector(new ServletModule() {
64-
@Override
65-
protected void configureServlets() {
66-
bind(TestServlet.class).annotatedWith(Names.named("foo"))
67-
.to(TestServlet.class).in(Scopes.SINGLETON);
68-
bind(TestServlet.class).annotatedWith(Names.named("bar"))
69-
.to(TestServlet.class).in(Scopes.SINGLETON);
70-
serve("/foo/*").with(Key.get(TestServlet.class, Names.named("foo")));
71-
serve("/bar/*").with(Key.get(TestServlet.class, Names.named("bar")));
72-
// TODO: add a filter(..) call and validate it is correct
73-
}
74-
});
61+
injector =
62+
Guice.createInjector(
63+
new ServletModule() {
64+
@Override
65+
protected void configureServlets() {
66+
bind(TestServlet.class)
67+
.annotatedWith(Names.named("foo"))
68+
.to(TestServlet.class)
69+
.in(Scopes.SINGLETON);
70+
bind(TestServlet.class)
71+
.annotatedWith(Names.named("bar"))
72+
.to(TestServlet.class)
73+
.in(Scopes.SINGLETON);
74+
serve("/foo/*").with(Key.get(TestServlet.class, Names.named("foo")));
75+
serve("/bar/*").with(Key.get(TestServlet.class, Names.named("bar")));
76+
// TODO: add a filter(..) call and validate it is correct
77+
}
78+
});
7579
injector.injectMembers(this);
7680

7781
assertNotNull(fooServlet);
@@ -83,7 +87,8 @@ protected void configureServlets() {
8387
filterConfig = globalControl.createMock(FilterConfig.class);
8488

8589
expect(servletContext.getAttribute(GuiceServletContextListener.INJECTOR_NAME))
86-
.andReturn(injector).anyTimes();
90+
.andReturn(injector)
91+
.anyTimes();
8792
expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes();
8893

8994
globalControl.replay();
@@ -229,8 +234,13 @@ public void testWebtestSpecific() throws Exception {
229234
runTest("/webtest/xxx", "/xxx", "/webtest", true, false, false);
230235
}
231236

232-
private void runTest(final String requestURI, final String servletPath, final String contextPath,
233-
final boolean filterResult, final boolean fooResult, final boolean barResult)
237+
private void runTest(
238+
final String requestURI,
239+
final String servletPath,
240+
final String contextPath,
241+
final boolean filterResult,
242+
final boolean fooResult,
243+
final boolean barResult)
234244
throws Exception {
235245
IMocksControl testControl = createControl();
236246

extensions/servlet/test/com/google/inject/servlet/ContinuingHttpServletRequestTest.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2013 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,16 +15,15 @@
1515
*/
1616
package com.google.inject.servlet;
1717

18-
import junit.framework.AssertionFailedError;
1918
import static org.easymock.EasyMock.createMock;
2019
import static org.easymock.EasyMock.expect;
2120
import static org.easymock.EasyMock.replay;
2221
import static org.easymock.EasyMock.verify;
2322

24-
import junit.framework.TestCase;
25-
2623
import javax.servlet.http.Cookie;
2724
import javax.servlet.http.HttpServletRequest;
25+
import junit.framework.AssertionFailedError;
26+
import junit.framework.TestCase;
2827

2928
public class ContinuingHttpServletRequestTest extends TestCase {
3029

@@ -42,19 +41,16 @@ public void testReturnNullCookiesIfDelegateHasNoNull() {
4241

4342
verify(delegate);
4443
}
45-
44+
4645
public void testReturnDelegateCookies() {
47-
Cookie[] cookies = new Cookie[]{
48-
new Cookie("testName1", TEST_VALUE_1),
49-
new Cookie("testName2", "testValue2")
50-
};
46+
Cookie[] cookies =
47+
new Cookie[] {new Cookie("testName1", TEST_VALUE_1), new Cookie("testName2", "testValue2")};
5148
HttpServletRequest delegate = createMock(HttpServletRequest.class);
5249
expect(delegate.getCookies()).andStubReturn(cookies);
5350

5451
replay(delegate);
5552

56-
ContinuingHttpServletRequest continuingRequest = new ContinuingHttpServletRequest(
57-
delegate);
53+
ContinuingHttpServletRequest continuingRequest = new ContinuingHttpServletRequest(delegate);
5854

5955
assertCookieArraysEqual(cookies, continuingRequest.getCookies());
6056

@@ -76,8 +72,8 @@ public void testReturnDelegateCookies() {
7672
assertEquals(DEFAULT_MAX_AGE, continuingRequest.getCookies()[1].getMaxAge());
7773

7874
// Perform a snapshot of the snapshot.
79-
ContinuingHttpServletRequest furtherContinuingRequest = new ContinuingHttpServletRequest(
80-
continuingRequest);
75+
ContinuingHttpServletRequest furtherContinuingRequest =
76+
new ContinuingHttpServletRequest(continuingRequest);
8177

8278
// The cookies should be fixed.
8379
assertCookieArraysEqual(continuingRequest.getCookies(), furtherContinuingRequest.getCookies());

extensions/servlet/test/com/google/inject/servlet/ContinuingRequestIntegrationTest.java

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2010 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,6 @@
1616

1717
package com.google.inject.servlet;
1818

19-
import javax.servlet.http.Cookie;
2019
import static org.easymock.EasyMock.createMock;
2120
import static org.easymock.EasyMock.expect;
2221
import static org.easymock.EasyMock.replay;
@@ -30,9 +29,6 @@
3029
import com.google.inject.Key;
3130
import com.google.inject.Provider;
3231
import com.google.inject.Singleton;
33-
34-
import junit.framework.TestCase;
35-
3632
import java.io.IOException;
3733
import java.util.List;
3834
import java.util.concurrent.AbstractExecutorService;
@@ -42,18 +38,17 @@
4238
import java.util.concurrent.Future;
4339
import java.util.concurrent.TimeUnit;
4440
import java.util.concurrent.atomic.AtomicBoolean;
45-
4641
import javax.servlet.FilterChain;
4742
import javax.servlet.FilterConfig;
4843
import javax.servlet.ServletContext;
4944
import javax.servlet.ServletException;
45+
import javax.servlet.http.Cookie;
5046
import javax.servlet.http.HttpServlet;
5147
import javax.servlet.http.HttpServletRequest;
5248
import javax.servlet.http.HttpServletResponse;
49+
import junit.framework.TestCase;
5350

54-
/**
55-
* Tests continuation of requests
56-
*/
51+
/** Tests continuation of requests */
5752

5853
public class ContinuingRequestIntegrationTest extends TestCase {
5954
private static final String PARAM_VALUE = "there";
@@ -108,21 +103,25 @@ public <T> Future<T> submit(Callable<T> task) {
108103
private ExecutorService executor;
109104
private Injector injector;
110105

111-
@Override protected void tearDown() throws Exception {
106+
@Override
107+
protected void tearDown() throws Exception {
112108
injector.getInstance(GuiceFilter.class).destroy();
113109
}
114110

115111
public final void testRequestContinuesInOtherThread()
116112
throws ServletException, IOException, InterruptedException {
117113
executor = Executors.newSingleThreadExecutor();
118114

119-
injector = Guice.createInjector(new ServletModule() {
120-
@Override protected void configureServlets() {
121-
serve("/*").with(ContinuingServlet.class);
115+
injector =
116+
Guice.createInjector(
117+
new ServletModule() {
118+
@Override
119+
protected void configureServlets() {
120+
serve("/*").with(ContinuingServlet.class);
122121

123-
bind(ExecutorService.class).toInstance(executor);
124-
}
125-
});
122+
bind(ExecutorService.class).toInstance(executor);
123+
}
124+
});
126125

127126
FilterConfig filterConfig = createMock(FilterConfig.class);
128127
expect(filterConfig.getServletContext()).andReturn(createMock(ServletContext.class));
@@ -132,9 +131,7 @@ public final void testRequestContinuesInOtherThread()
132131
HttpServletRequest request = createMock(HttpServletRequest.class);
133132

134133
expect(request.getRequestURI()).andReturn("/");
135-
expect(request.getContextPath())
136-
.andReturn("")
137-
.anyTimes();
134+
expect(request.getContextPath()).andReturn("").anyTimes();
138135
expect(request.getMethod()).andReturn("GET");
139136
expect(request.getCookies()).andReturn(new Cookie[0]);
140137

@@ -157,15 +154,18 @@ public final void testRequestContinuesInOtherThread()
157154
public final void testRequestContinuationDiesInHttpRequestThread()
158155
throws ServletException, IOException, InterruptedException {
159156
executor = sameThreadExecutor;
160-
injector = Guice.createInjector(new ServletModule() {
161-
@Override protected void configureServlets() {
162-
serve("/*").with(ContinuingServlet.class);
157+
injector =
158+
Guice.createInjector(
159+
new ServletModule() {
160+
@Override
161+
protected void configureServlets() {
162+
serve("/*").with(ContinuingServlet.class);
163163

164-
bind(ExecutorService.class).toInstance(executor);
164+
bind(ExecutorService.class).toInstance(executor);
165165

166-
bind(SomeObject.class);
167-
}
168-
});
166+
bind(SomeObject.class);
167+
}
168+
});
169169

170170
FilterConfig filterConfig = createMock(FilterConfig.class);
171171
expect(filterConfig.getServletContext()).andReturn(createMock(ServletContext.class));
@@ -175,9 +175,7 @@ public final void testRequestContinuationDiesInHttpRequestThread()
175175
HttpServletRequest request = createMock(HttpServletRequest.class);
176176

177177
expect(request.getRequestURI()).andReturn("/");
178-
expect(request.getContextPath())
179-
.andReturn("")
180-
.anyTimes();
178+
expect(request.getContextPath()).andReturn("").anyTimes();
181179

182180
expect(request.getMethod()).andReturn("GET");
183181
expect(request.getCookies()).andReturn(new Cookie[0]);
@@ -199,8 +197,7 @@ public final void testRequestContinuationDiesInHttpRequestThread()
199197
}
200198

201199
@RequestScoped
202-
public static class SomeObject {
203-
}
200+
public static class SomeObject {}
204201

205202
@Singleton
206203
public static class ContinuingServlet extends HttpServlet {
@@ -209,14 +206,16 @@ public static class ContinuingServlet extends HttpServlet {
209206

210207
private SomeObject someObject;
211208

212-
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp)
209+
@Override
210+
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
213211
throws ServletException, IOException {
214212
assertNull(someObject);
215213

216214
// Seed with someobject.
217215
someObject = new SomeObject();
218-
Callable<String> task = ServletScopes.continueRequest(callable,
219-
ImmutableMap.<Key<?>, Object>of(Key.get(SomeObject.class), someObject));
216+
Callable<String> task =
217+
ServletScopes.continueRequest(
218+
callable, ImmutableMap.<Key<?>, Object>of(Key.get(SomeObject.class), someObject));
220219

221220
executorService.submit(task);
222221
}

extensions/servlet/test/com/google/inject/servlet/DummyFilterImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2008 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
1717
package com.google.inject.servlet;
1818

1919
import java.io.IOException;
20-
2120
import javax.servlet.Filter;
2221
import javax.servlet.FilterChain;
2322
import javax.servlet.FilterConfig;
@@ -33,8 +32,7 @@
3332
public class DummyFilterImpl implements Filter {
3433
int num;
3534

36-
public DummyFilterImpl() {
37-
}
35+
public DummyFilterImpl() {}
3836

3937
public DummyFilterImpl(int num) {
4038
this.num = num;

extensions/servlet/test/com/google/inject/servlet/DummyServlet.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright (C) 2008 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,7 +16,6 @@
1616
package com.google.inject.servlet;
1717

1818
import com.google.inject.Singleton;
19-
2019
import javax.servlet.http.HttpServlet;
2120

2221
/**
@@ -25,6 +24,4 @@
2524
* @author Dhanji R. Prasanna (dhanji@gmail com)
2625
*/
2726
@Singleton
28-
public class DummyServlet extends HttpServlet {
29-
30-
}
27+
public class DummyServlet extends HttpServlet {}

0 commit comments

Comments
 (0)