Skip to content

Commit da81601

Browse files
committed
Address JavaFormat Violations in Test Support
Issue gh-743
1 parent 3a70cfb commit da81601

12 files changed

+123
-125
lines changed

test-support/src/main/java/org/springframework/ldap/test/AbstractEc2InstanceLaunchingFactoryBean.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,36 +109,38 @@ public void setGroupName(String groupName) {
109109

110110
@Override
111111
protected final Object createInstance() throws Exception {
112-
Assert.hasLength(imageName, "ImageName must be set");
113-
Assert.hasLength(awsKey, "AwsKey must be set");
114-
Assert.hasLength(awsSecretKey, "AwsSecretKey must be set");
115-
Assert.hasLength(keypairName, "KeyName must be set");
116-
Assert.hasLength(groupName, "GroupName must be set");
112+
Assert.hasLength(this.imageName, "ImageName must be set");
113+
Assert.hasLength(this.awsKey, "AwsKey must be set");
114+
Assert.hasLength(this.awsSecretKey, "AwsSecretKey must be set");
115+
Assert.hasLength(this.keypairName, "KeyName must be set");
116+
Assert.hasLength(this.groupName, "GroupName must be set");
117117

118-
LOG.info("Launching EC2 instance for image: " + imageName);
118+
LOG.info("Launching EC2 instance for image: " + this.imageName);
119119

120-
Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
121-
LaunchConfiguration launchConfiguration = new LaunchConfiguration(imageName);
122-
launchConfiguration.setKeyName(keypairName);
123-
launchConfiguration.setSecurityGroup(Collections.singletonList(groupName));
120+
Jec2 jec2 = new Jec2(this.awsKey, this.awsSecretKey);
121+
LaunchConfiguration launchConfiguration = new LaunchConfiguration(this.imageName);
122+
launchConfiguration.setKeyName(this.keypairName);
123+
launchConfiguration.setSecurityGroup(Collections.singletonList(this.groupName));
124124

125125
ReservationDescription reservationDescription = jec2.runInstances(launchConfiguration);
126-
instance = reservationDescription.getInstances().get(0);
127-
while (!instance.isRunning() && !instance.isTerminated()) {
126+
this.instance = reservationDescription.getInstances().get(0);
127+
while (!this.instance.isRunning() && !this.instance.isTerminated()) {
128128
LOG.info("Instance still starting up; sleeping " + INSTANCE_START_SLEEP_TIME + "ms");
129129
Thread.sleep(INSTANCE_START_SLEEP_TIME);
130-
reservationDescription = jec2.describeInstances(Collections.singletonList(instance.getInstanceId())).get(0);
131-
instance = reservationDescription.getInstances().get(0);
130+
reservationDescription = jec2.describeInstances(Collections.singletonList(this.instance.getInstanceId()))
131+
.get(0);
132+
this.instance = reservationDescription.getInstances().get(0);
132133
}
133134

134-
if (instance.isRunning()) {
135+
if (this.instance.isRunning()) {
135136
LOG.info("EC2 instance is now running");
136-
if (preparationSleepTime > 0) {
137-
LOG.info("Sleeping " + preparationSleepTime + "ms allowing instance services to start up properly.");
138-
Thread.sleep(preparationSleepTime);
137+
if (this.preparationSleepTime > 0) {
138+
LOG.info("Sleeping " + this.preparationSleepTime
139+
+ "ms allowing instance services to start up properly.");
140+
Thread.sleep(this.preparationSleepTime);
139141
LOG.info("Instance prepared - proceeding");
140142
}
141-
return doCreateInstance(instance.getDnsName());
143+
return doCreateInstance(this.instance.getDnsName());
142144
}
143145
else {
144146
throw new IllegalStateException("Failed to start a new instance");
@@ -158,7 +160,7 @@ protected final Object createInstance() throws Exception {
158160
protected void destroyInstance(Object ignored) throws Exception {
159161
if (this.instance != null) {
160162
LOG.info("Shutting down instance");
161-
Jec2 jec2 = new Jec2(awsKey, awsSecretKey);
163+
Jec2 jec2 = new Jec2(this.awsKey, this.awsSecretKey);
162164
jec2.terminateInstances(Collections.singletonList(this.instance.getInstanceId()));
163165
}
164166

test-support/src/main/java/org/springframework/ldap/test/AttributeCheckAttributesMapper.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,18 @@ public class AttributeCheckAttributesMapper implements AttributesMapper<Object>
3737

3838
private String[] expectedValues = new String[0];
3939

40-
;
41-
4240
private String[] absentAttributes = new String[0];
4341

44-
;
45-
4642
public Object mapFromAttributes(Attributes attributes) throws NamingException {
47-
Assert.assertEquals("Values and attributes need to have the same length ", expectedAttributes.length,
48-
expectedValues.length);
49-
for (int i = 0; i < expectedAttributes.length; i++) {
50-
Attribute attribute = attributes.get(expectedAttributes[i]);
51-
Assert.assertNotNull("Attribute " + expectedAttributes[i] + " was not present", attribute);
52-
Assert.assertEquals(expectedValues[i], attribute.get());
43+
Assert.assertEquals("Values and attributes need to have the same length ", this.expectedAttributes.length,
44+
this.expectedValues.length);
45+
for (int i = 0; i < this.expectedAttributes.length; i++) {
46+
Attribute attribute = attributes.get(this.expectedAttributes[i]);
47+
Assert.assertNotNull("Attribute " + this.expectedAttributes[i] + " was not present", attribute);
48+
Assert.assertEquals(this.expectedValues[i], attribute.get());
5349
}
5450

55-
for (String absentAttribute : absentAttributes) {
51+
for (String absentAttribute : this.absentAttributes) {
5652
Assert.assertNull(attributes.get(absentAttribute));
5753
}
5854

@@ -71,4 +67,4 @@ public void setExpectedValues(String[] expectedValues) {
7167
this.expectedValues = Arrays.copyOf(expectedValues, expectedValues.length);
7268
}
7369

74-
}
70+
}

test-support/src/main/java/org/springframework/ldap/test/AttributeCheckContextMapper.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public class AttributeCheckContextMapper implements ContextMapper<DirContextAdap
3838

3939
public DirContextAdapter mapFromContext(Object ctx) {
4040
DirContextAdapter adapter = (DirContextAdapter) ctx;
41-
Assert.assertEquals("Values and attributes need to have the same length ", expectedAttributes.length,
42-
expectedValues.length);
43-
for (int i = 0; i < expectedAttributes.length; i++) {
44-
String attributeValue = adapter.getStringAttribute(expectedAttributes[i]);
45-
Assert.assertNotNull("Attribute " + expectedAttributes[i] + " was not present", attributeValue);
46-
Assert.assertEquals(expectedValues[i], attributeValue);
41+
Assert.assertEquals("Values and attributes need to have the same length ", this.expectedAttributes.length,
42+
this.expectedValues.length);
43+
for (int i = 0; i < this.expectedAttributes.length; i++) {
44+
String attributeValue = adapter.getStringAttribute(this.expectedAttributes[i]);
45+
Assert.assertNotNull("Attribute " + this.expectedAttributes[i] + " was not present", attributeValue);
46+
Assert.assertEquals(this.expectedValues[i], attributeValue);
4747
}
4848

49-
for (String absentAttribute : absentAttributes) {
49+
for (String absentAttribute : this.absentAttributes) {
5050
Assert.assertNull(adapter.getStringAttribute(absentAttribute));
5151
}
5252

test-support/src/main/java/org/springframework/ldap/test/ContextSourceEc2InstanceLaunchingFactoryBean.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public final Class getObjectType() {
3939

4040
@Override
4141
protected final Object doCreateInstance(final String dnsName) throws Exception {
42-
Assert.hasText(userDn);
42+
Assert.hasText(this.userDn);
4343
LdapContextSource instance = new LdapContextSource();
4444
instance.setUrl("ldap://" + dnsName);
45-
instance.setUserDn(userDn);
46-
instance.setPassword(password);
47-
instance.setBase(base);
48-
instance.setPooled(pooled);
45+
instance.setUserDn(this.userDn);
46+
instance.setPassword(this.password);
47+
instance.setBase(this.base);
48+
instance.setPooled(this.pooled);
4949
setAdditionalContextSourceProperties(instance, dnsName);
5050

5151
instance.afterPropertiesSet();

test-support/src/main/java/org/springframework/ldap/test/EmbeddedLdapServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public static EmbeddedLdapServer newEmbeddedServer(String defaultPartitionName,
8484
}
8585

8686
public void shutdown() throws Exception {
87-
ldapServer.stop();
88-
directoryService.shutdown();
87+
this.ldapServer.stop();
88+
this.directoryService.shutdown();
8989

9090
FileUtils.deleteDirectory(workingDirectory);
9191
}

test-support/src/main/java/org/springframework/ldap/test/EmbeddedLdapServerFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void setPort(int port) {
4848

4949
@Override
5050
protected EmbeddedLdapServer createInstance() throws Exception {
51-
return EmbeddedLdapServer.newEmbeddedServer(partitionName, partitionSuffix, port);
51+
return EmbeddedLdapServer.newEmbeddedServer(this.partitionName, this.partitionSuffix, this.port);
5252
}
5353

5454
@Override

test-support/src/main/java/org/springframework/ldap/test/LdapTestUtils.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ public static void startEmbeddedServer(int port, String defaultPartitionSuffix,
104104
try {
105105
embeddedServer = EmbeddedLdapServer.newEmbeddedServer(defaultPartitionName, defaultPartitionSuffix, port);
106106
}
107-
catch (Exception e) {
108-
throw new UncategorizedLdapException("Failed to start embedded server", e);
107+
catch (Exception ex) {
108+
throw new UncategorizedLdapException("Failed to start embedded server", ex);
109109
}
110110
}
111111

@@ -159,7 +159,7 @@ public static void clearSubContexts(ContextSource contextSource, Name name) thro
159159
try {
160160
ctx.close();
161161
}
162-
catch (Exception e) {
162+
catch (Exception ex) {
163163
// Never mind this
164164
}
165165
}
@@ -185,20 +185,20 @@ public static void clearSubContexts(DirContext ctx, Name name) throws NamingExce
185185
try {
186186
ctx.unbind(childName);
187187
}
188-
catch (ContextNotEmptyException e) {
188+
catch (ContextNotEmptyException ex) {
189189
clearSubContexts(ctx, childName);
190190
ctx.unbind(childName);
191191
}
192192
}
193193
}
194-
catch (NamingException e) {
195-
LOGGER.debug("Error cleaning sub-contexts", e);
194+
catch (NamingException ex) {
195+
LOGGER.debug("Error cleaning sub-contexts", ex);
196196
}
197197
finally {
198198
try {
199199
enumeration.close();
200200
}
201-
catch (Exception e) {
201+
catch (Exception ex) {
202202
// Never mind this
203203
}
204204
}
@@ -220,7 +220,7 @@ public static void loadLdif(ContextSource contextSource, Resource ldifFile) thro
220220
try {
221221
context.close();
222222
}
223-
catch (Exception e) {
223+
catch (Exception ex) {
224224
// This is not the exception we are interested in.
225225
}
226226
}
@@ -258,8 +258,8 @@ private static void loadLdif(DirContext context, Name rootNode, Resource ldifFil
258258
context.bind(dn, null, record);
259259
}
260260
}
261-
catch (Exception e) {
262-
throw new UncategorizedLdapException("Failed to populate LDIF", e);
261+
catch (Exception ex) {
262+
throw new UncategorizedLdapException("Failed to populate LDIF", ex);
263263
}
264264
}
265265

@@ -275,7 +275,7 @@ public static void loadLdif(DefaultDirectoryService directoryService, Resource l
275275
try {
276276
tempFile.delete();
277277
}
278-
catch (Exception e) {
278+
catch (Exception ex) {
279279
// Ignore this
280280
}
281281
}

test-support/src/main/java/org/springframework/ldap/test/LdifPopulator.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,27 @@ public void setDefaultBase(String defaultBase) {
6868

6969
@Override
7070
public void afterPropertiesSet() throws Exception {
71-
Assert.notNull(contextSource, "ContextSource must be specified");
72-
Assert.notNull(resource, "Resource must be specified");
71+
Assert.notNull(this.contextSource, "ContextSource must be specified");
72+
Assert.notNull(this.resource, "Resource must be specified");
7373

74-
if (!LdapUtils.newLdapName(base).equals(LdapUtils.newLdapName(defaultBase))) {
75-
List<String> lines = IOUtils.readLines(resource.getInputStream());
74+
if (!LdapUtils.newLdapName(this.base).equals(LdapUtils.newLdapName(this.defaultBase))) {
75+
List<String> lines = IOUtils.readLines(this.resource.getInputStream());
7676

7777
StringWriter sw = new StringWriter();
7878
PrintWriter writer = new PrintWriter(sw);
7979
for (String line : lines) {
80-
writer.println(StringUtils.replace(line, defaultBase, base));
80+
writer.println(StringUtils.replace(line, this.defaultBase, this.base));
8181
}
8282

8383
writer.flush();
84-
resource = new ByteArrayResource(sw.toString().getBytes("UTF8"));
84+
this.resource = new ByteArrayResource(sw.toString().getBytes("UTF8"));
8585
}
8686

87-
if (clean) {
88-
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.emptyLdapName());
87+
if (this.clean) {
88+
LdapTestUtils.clearSubContexts(this.contextSource, LdapUtils.emptyLdapName());
8989
}
9090

91-
LdapTestUtils.loadLdif(contextSource, resource);
91+
LdapTestUtils.loadLdif(this.contextSource, this.resource);
9292
}
9393

9494
}

test-support/src/main/java/org/springframework/ldap/test/TestContextSourceFactoryBean.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,43 +96,43 @@ public void setContextSource(ContextSource contextSource) {
9696
}
9797

9898
protected Object createInstance() throws Exception {
99-
LdapTestUtils.startEmbeddedServer(port, defaultPartitionSuffix, defaultPartitionName);
99+
LdapTestUtils.startEmbeddedServer(this.port, this.defaultPartitionSuffix, this.defaultPartitionName);
100100

101-
if (contextSource == null) {
101+
if (this.contextSource == null) {
102102
// If not explicitly configured, create a new instance.
103103
LdapContextSource targetContextSource = new LdapContextSource();
104-
if (baseOnTarget) {
105-
targetContextSource.setBase(defaultPartitionSuffix);
104+
if (this.baseOnTarget) {
105+
targetContextSource.setBase(this.defaultPartitionSuffix);
106106
}
107107

108-
targetContextSource.setUrl("ldap://localhost:" + port);
109-
targetContextSource.setUserDn(principal);
110-
targetContextSource.setPassword(password);
111-
targetContextSource.setDirObjectFactory(dirObjectFactory);
112-
targetContextSource.setPooled(pooled);
108+
targetContextSource.setUrl("ldap://localhost:" + this.port);
109+
targetContextSource.setUserDn(this.principal);
110+
targetContextSource.setPassword(this.password);
111+
targetContextSource.setDirObjectFactory(this.dirObjectFactory);
112+
targetContextSource.setPooled(this.pooled);
113113

114-
if (authenticationSource != null) {
115-
targetContextSource.setAuthenticationSource(authenticationSource);
114+
if (this.authenticationSource != null) {
115+
targetContextSource.setAuthenticationSource(this.authenticationSource);
116116
}
117117
targetContextSource.afterPropertiesSet();
118118

119-
contextSource = targetContextSource;
119+
this.contextSource = targetContextSource;
120120
}
121121

122122
Thread.sleep(1000);
123123

124-
if (baseOnTarget) {
125-
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.emptyLdapName());
124+
if (this.baseOnTarget) {
125+
LdapTestUtils.clearSubContexts(this.contextSource, LdapUtils.emptyLdapName());
126126
}
127127
else {
128-
LdapTestUtils.clearSubContexts(contextSource, LdapUtils.newLdapName(defaultPartitionSuffix));
128+
LdapTestUtils.clearSubContexts(this.contextSource, LdapUtils.newLdapName(this.defaultPartitionSuffix));
129129
}
130130

131-
if (ldifFile != null) {
132-
LdapTestUtils.loadLdif(contextSource, ldifFile);
131+
if (this.ldifFile != null) {
132+
LdapTestUtils.loadLdif(this.contextSource, this.ldifFile);
133133
}
134134

135-
return contextSource;
135+
return this.contextSource;
136136
}
137137

138138
public Class getObjectType() {

0 commit comments

Comments
 (0)