Skip to content

Commit 8da35be

Browse files
committed
formatting and fixes
Issue #1058 Signed-off-by: etrandafir93 <[email protected]>
1 parent ca10190 commit 8da35be

File tree

6 files changed

+36
-47
lines changed

6 files changed

+36
-47
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
import javax.naming.directory.Attribute;
2323
import javax.naming.directory.Attributes;
2424

25-
import org.springframework.ldap.core.AttributesMapper;
25+
import junit.framework.Assert;
2626

27-
import static org.junit.jupiter.api.Assertions.assertEquals;
28-
import static org.junit.jupiter.api.Assertions.assertNotNull;
29-
import static org.junit.jupiter.api.Assertions.assertNull;
27+
import org.springframework.ldap.core.AttributesMapper;
3028

3129
/**
3230
* Dummy AttributesMapper for testing purposes to check that the received Attributes are
@@ -43,17 +41,16 @@ public class AttributeCheckAttributesMapper implements AttributesMapper<Object>
4341
private String[] absentAttributes = new String[0];
4442

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

5552
for (String absentAttribute : this.absentAttributes) {
56-
assertNull(attributes.get(absentAttribute));
53+
Assert.assertNull(attributes.get(absentAttribute));
5754
}
5855

5956
return new Object();

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818

1919
import java.util.Arrays;
2020

21-
import org.springframework.ldap.core.ContextMapper;
21+
import junit.framework.Assert;
2222

23+
import org.springframework.ldap.core.ContextMapper;
2324
import org.springframework.ldap.core.DirContextAdapter;
2425

25-
import static org.junit.jupiter.api.Assertions.assertEquals;
26-
import static org.junit.jupiter.api.Assertions.assertNotNull;
27-
import static org.junit.jupiter.api.Assertions.assertNull;
28-
2926
/**
3027
* Dummy ContextMapper for testing purposes to check that the received Attributes are the
3128
* expected ones.
@@ -42,17 +39,16 @@ public class AttributeCheckContextMapper implements ContextMapper<DirContextAdap
4239

4340
public DirContextAdapter mapFromContext(Object ctx) {
4441
DirContextAdapter adapter = (DirContextAdapter) ctx;
45-
assertEquals(this.expectedAttributes.length,
46-
this.expectedValues.length,
47-
"Values and attributes need to have the same length ");
42+
Assert.assertEquals("Values and attributes need to have the same length ", this.expectedAttributes.length,
43+
this.expectedValues.length);
4844
for (int i = 0; i < this.expectedAttributes.length; i++) {
4945
String attributeValue = adapter.getStringAttribute(this.expectedAttributes[i]);
50-
assertNotNull(attributeValue, "Attribute " + this.expectedAttributes[i] + " was not present");
51-
assertEquals(this.expectedValues[i], attributeValue);
46+
Assert.assertNotNull("Attribute " + this.expectedAttributes[i] + " was not present", attributeValue);
47+
Assert.assertEquals(this.expectedValues[i], attributeValue);
5248
}
5349

5450
for (String absentAttribute : this.absentAttributes) {
55-
assertNull(adapter.getStringAttribute(absentAttribute));
51+
Assert.assertNull(adapter.getStringAttribute(absentAttribute));
5652
}
5753

5854
return adapter;

test-support/src/test/java/org/springframework/ldap/test/EmbeddedLdapServerFactoryBeanTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
import javax.naming.NamingException;
2222
import javax.naming.directory.Attributes;
2323

24-
import org.springframework.context.support.ClassPathXmlApplicationContext;
25-
2624
import org.junit.jupiter.api.Test;
27-
import org.springframework.ldap.core.AttributesMapper;
25+
26+
import org.springframework.context.support.ClassPathXmlApplicationContext;
2827
import org.springframework.ldap.core.LdapTemplate;
2928
import org.springframework.ldap.query.LdapQueryBuilder;
3029

@@ -39,12 +38,12 @@ void serverStartup() throws Exception {
3938
assertThat(ldapTemplate).isNotNull();
4039

4140
List<String> list = ldapTemplate.search(LdapQueryBuilder.query().where("objectclass").is("person"),
42-
new AttributesMapper<>() {
43-
public String mapFromAttributes(Attributes attrs) throws NamingException {
44-
return (String) attrs.get("cn").get();
45-
}
46-
});
41+
this::mapFromAttributes);
4742
assertThat(5).isEqualTo(list.size());
4843
}
4944

45+
private String mapFromAttributes(Attributes attrs) throws NamingException {
46+
return (String) attrs.get("cn").get();
47+
}
48+
5049
}

test-support/src/test/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServerFactoryBeanTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.junit.jupiter.api.Test;
2626

2727
import org.springframework.context.support.ClassPathXmlApplicationContext;
28-
import org.springframework.ldap.core.AttributesMapper;
2928
import org.springframework.ldap.core.LdapTemplate;
3029
import org.springframework.ldap.query.LdapQueryBuilder;
3130

@@ -49,12 +48,12 @@ void serverStartup() throws Exception {
4948
assertThat(ldapTemplate).isNotNull();
5049

5150
List<String> list = ldapTemplate.search(LdapQueryBuilder.query().where("objectclass").is("person"),
52-
new AttributesMapper<>() {
53-
public String mapFromAttributes(Attributes attrs) throws NamingException {
54-
return (String) attrs.get("cn").get();
55-
}
56-
});
51+
this::mapFromAttributes);
5752
assertThat(list.size()).isEqualTo(5);
5853
}
5954

55+
private String mapFromAttributes(Attributes attrs) throws NamingException {
56+
return (String) attrs.get("cn").get();
57+
}
58+
6059
}

test-support/src/test/java/org/springframework/ldap/test/unboundid/EmbeddedLdapServerTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.junit.jupiter.api.BeforeEach;
3232
import org.junit.jupiter.api.Test;
3333

34-
import org.springframework.ldap.core.AttributesMapper;
3534
import org.springframework.ldap.core.LdapTemplate;
3635
import org.springframework.ldap.core.support.LdapContextSource;
3736
import org.springframework.ldap.query.LdapQueryBuilder;
@@ -140,11 +139,7 @@ void shouldBuildLdapServerAndApplyCustomConfiguration() throws IOException {
140139
server.start();
141140

142141
ldapTemplate("dc=jayway,dc=se", this.port)
143-
.search(LdapQueryBuilder.query().where("objectclass").is("person"), new AttributesMapper<>() {
144-
public String mapFromAttributes(Attributes attrs) throws NamingException {
145-
return (String) attrs.get("cn").get();
146-
}
147-
});
142+
.search(LdapQueryBuilder.query().where("objectclass").is("person"), this::mapFromAttributes);
148143
}
149144

150145
assertThat(Path.of(tempLogFile))
@@ -185,4 +180,8 @@ static LdapTemplate ldapTemplate(String base, int port) {
185180
return new LdapTemplate(ctx);
186181
}
187182

183+
private String mapFromAttributes(Attributes attrs) throws NamingException {
184+
return (String) attrs.get("cn").get();
185+
}
186+
188187
}

test-support/src/test/java/org/springframework/ldap/test/unboundid/TestContextSourceFactoryBeanTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.junit.jupiter.api.Test;
2626

2727
import org.springframework.context.support.ClassPathXmlApplicationContext;
28-
import org.springframework.ldap.core.AttributesMapper;
2928
import org.springframework.ldap.core.LdapTemplate;
3029
import org.springframework.ldap.query.LdapQueryBuilder;
3130

@@ -49,12 +48,12 @@ void serverStartup() throws Exception {
4948
assertThat(ldapTemplate).isNotNull();
5049

5150
List<String> list = ldapTemplate.search(LdapQueryBuilder.query().where("objectclass").is("person"),
52-
new AttributesMapper<>() {
53-
public String mapFromAttributes(Attributes attrs) throws NamingException {
54-
return (String) attrs.get("cn").get();
55-
}
56-
});
51+
this::mapFromAttributes);
5752
assertThat(list.size()).isEqualTo(5);
5853
}
5954

55+
private String mapFromAttributes(Attributes attrs) throws NamingException {
56+
return (String) attrs.get("cn").get();
57+
}
58+
6059
}

0 commit comments

Comments
 (0)