Skip to content

Commit 38be600

Browse files
committed
migrate to junit5
Issue #1058 Signed-off-by: etrandafir93 <[email protected]>
1 parent ae34a65 commit 38be600

File tree

7 files changed

+29
-27
lines changed

7 files changed

+29
-27
lines changed

test-support/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ dependencies {
2121
optional "org.apache.directory.shared:shared-ldap"
2222
optional "com.unboundid:unboundid-ldapsdk"
2323

24-
provided "junit:junit"
25-
testImplementation platform('org.junit:junit-bom')
26-
testImplementation "org.junit.vintage:junit-vintage-engine"
24+
provided "org.junit.jupiter:junit-jupiter-api"
25+
testImplementation "org.junit.jupiter:junit-jupiter-engine"
26+
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
2727
testImplementation "org.assertj:assertj-core"
2828
}

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

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

25-
import junit.framework.Assert;
26-
2725
import org.springframework.ldap.core.AttributesMapper;
26+
import org.springframework.util.Assert;
2827

2928
/**
3029
* Dummy AttributesMapper for testing purposes to check that the received Attributes are
@@ -41,16 +40,18 @@ public class AttributeCheckAttributesMapper implements AttributesMapper<Object>
4140
private String[] absentAttributes = new String[0];
4241

4342
public Object mapFromAttributes(Attributes attributes) throws NamingException {
44-
Assert.assertEquals("Values and attributes need to have the same length ", this.expectedAttributes.length,
45-
this.expectedValues.length);
43+
Assert.isTrue(this.expectedAttributes.length == this.expectedValues.length,
44+
"Values and attributes need to have the same length");
4645
for (int i = 0; i < this.expectedAttributes.length; i++) {
4746
Attribute attribute = attributes.get(this.expectedAttributes[i]);
48-
Assert.assertNotNull("Attribute " + this.expectedAttributes[i] + " was not present", attribute);
49-
Assert.assertEquals(this.expectedValues[i], attribute.get());
47+
Assert.notNull(attribute, "Attribute " + this.expectedAttributes[i] + " was not present");
48+
Object value = attribute.get();
49+
Assert.isTrue(this.expectedValues[i].equals(value),
50+
"Expected '" + this.expectedValues[i] + "' but got '" + value + "'");
5051
}
5152

5253
for (String absentAttribute : this.absentAttributes) {
53-
Assert.assertNull(attributes.get(absentAttribute));
54+
Assert.isNull(attributes.get(absentAttribute), "Attribute '" + absentAttribute + "' should not be present");
5455
}
5556

5657
return new Object();

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818

1919
import java.util.Arrays;
2020

21-
import junit.framework.Assert;
22-
2321
import org.springframework.ldap.core.ContextMapper;
2422
import org.springframework.ldap.core.DirContextAdapter;
23+
import org.springframework.util.Assert;
2524

2625
/**
2726
* Dummy ContextMapper for testing purposes to check that the received Attributes are the
@@ -39,16 +38,18 @@ public class AttributeCheckContextMapper implements ContextMapper<DirContextAdap
3938

4039
public DirContextAdapter mapFromContext(Object ctx) {
4140
DirContextAdapter adapter = (DirContextAdapter) ctx;
42-
Assert.assertEquals("Values and attributes need to have the same length ", this.expectedAttributes.length,
43-
this.expectedValues.length);
41+
Assert.isTrue(this.expectedAttributes.length == this.expectedValues.length,
42+
"Values and attributes need to have the same length");
4443
for (int i = 0; i < this.expectedAttributes.length; i++) {
4544
String attributeValue = adapter.getStringAttribute(this.expectedAttributes[i]);
46-
Assert.assertNotNull("Attribute " + this.expectedAttributes[i] + " was not present", attributeValue);
47-
Assert.assertEquals(this.expectedValues[i], attributeValue);
45+
Assert.notNull(attributeValue, "Attribute " + this.expectedAttributes[i] + " was not present");
46+
Assert.isTrue(this.expectedValues[i].equals(attributeValue),
47+
"Expected '" + this.expectedValues[i] + "' but got '" + attributeValue + "'");
4848
}
4949

5050
for (String absentAttribute : this.absentAttributes) {
51-
Assert.assertNull(adapter.getStringAttribute(absentAttribute));
51+
Assert.isNull(adapter.getStringAttribute(absentAttribute),
52+
"Attribute '" + absentAttribute + "' should not be present");
5253
}
5354

5455
return adapter;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import javax.naming.NamingException;
2222
import javax.naming.directory.Attributes;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.context.support.ClassPathXmlApplicationContext;
2727
import org.springframework.ldap.core.AttributesMapper;

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

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

24-
import org.junit.After;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.springframework.context.support.ClassPathXmlApplicationContext;
2828
import org.springframework.ldap.core.AttributesMapper;
@@ -35,7 +35,7 @@ public class EmbeddedLdapServerFactoryBeanTests {
3535

3636
ClassPathXmlApplicationContext ctx;
3737

38-
@After
38+
@AfterEach
3939
public void setup() {
4040
if (this.ctx != null) {
4141
this.ctx.close();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
import com.unboundid.ldap.listener.InMemoryDirectoryServer;
2929
import com.unboundid.ldap.listener.InMemoryDirectoryServerConfig;
3030
import com.unboundid.ldap.listener.InMemoryListenerConfig;
31-
import org.junit.Before;
32-
import org.junit.Test;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
3333

3434
import org.springframework.ldap.core.AttributesMapper;
3535
import org.springframework.ldap.core.LdapTemplate;
@@ -43,7 +43,7 @@ public class EmbeddedLdapServerTests {
4343

4444
private int port;
4545

46-
@Before
46+
@BeforeEach
4747
public void setUp() throws IOException {
4848
this.port = getFreePort();
4949
}

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

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

24-
import org.junit.After;
25-
import org.junit.Test;
24+
import org.junit.jupiter.api.AfterEach;
25+
import org.junit.jupiter.api.Test;
2626

2727
import org.springframework.context.support.ClassPathXmlApplicationContext;
2828
import org.springframework.ldap.core.AttributesMapper;
@@ -35,7 +35,7 @@ public class TestContextSourceFactoryBeanTests {
3535

3636
ClassPathXmlApplicationContext ctx;
3737

38-
@After
38+
@AfterEach
3939
public void setup() {
4040
if (this.ctx != null) {
4141
this.ctx.close();

0 commit comments

Comments
 (0)