Skip to content

Commit 2f7dccc

Browse files
ahornaceVladimir Kotal
authored andcommitted
Use junit5 in plugins
1 parent 7ef04fd commit 2f7dccc

33 files changed

+250
-209
lines changed

plugins/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ Portions Copyright (c) 2020, Chris Fraire <[email protected]>.
6060
<scope>test</scope>
6161
</dependency>
6262
<dependency>
63-
<groupId>org.junit.vintage</groupId>
64-
<artifactId>junit-vintage-engine</artifactId>
63+
<groupId>org.junit.jupiter</groupId>
64+
<artifactId>junit-jupiter-params</artifactId>
6565
<scope>test</scope>
6666
</dependency>
6767
<dependency>

plugins/src/test/java/opengrok/auth/plugin/FalsePluginTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
package opengrok.auth.plugin;
2424

2525
import opengrok.auth.plugin.entity.User;
26-
import org.junit.Before;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2828
import org.opengrok.indexer.configuration.Group;
2929
import org.opengrok.indexer.configuration.Project;
3030
import org.opengrok.indexer.util.RandomString;
@@ -39,7 +39,7 @@ public class FalsePluginTest {
3939

4040
private FalsePlugin plugin;
4141

42-
@Before
42+
@BeforeEach
4343
public void setUp() {
4444
plugin = new FalsePlugin();
4545
}

plugins/src/test/java/opengrok/auth/plugin/LdapAttrPluginTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package opengrok.auth.plugin;
2424

@@ -44,16 +44,16 @@
4444
import opengrok.auth.plugin.ldap.LdapException;
4545
import opengrok.auth.plugin.ldap.LdapFacade;
4646
import opengrok.auth.plugin.util.DummyHttpServletRequestLdap;
47-
import org.junit.AfterClass;
48-
import org.junit.Assert;
49-
import org.junit.Before;
50-
import org.junit.BeforeClass;
51-
import org.junit.Test;
47+
import org.junit.jupiter.api.AfterAll;
48+
import org.junit.jupiter.api.BeforeAll;
49+
import org.junit.jupiter.api.BeforeEach;
50+
import org.junit.jupiter.api.Test;
5251
import org.opengrok.indexer.configuration.Group;
5352
import org.opengrok.indexer.configuration.Project;
5453

55-
import static org.junit.Assert.assertNotNull;
56-
import static org.junit.Assert.assertTrue;
54+
import static org.junit.jupiter.api.Assertions.assertFalse;
55+
import static org.junit.jupiter.api.Assertions.assertNotNull;
56+
import static org.junit.jupiter.api.Assertions.assertTrue;
5757
import static org.mockito.ArgumentMatchers.any;
5858
import static org.mockito.ArgumentMatchers.anyString;
5959
import static org.mockito.Mockito.mock;
@@ -66,7 +66,7 @@ public class LdapAttrPluginTest {
6666

6767
private static File whitelistFile;
6868

69-
@BeforeClass
69+
@BeforeAll
7070
public static void beforeClass() throws IOException {
7171
whitelistFile = Files.createTempFile("opengrok-auth-", "-check.tmp").toFile();
7272
try (Writer w = new OutputStreamWriter(new FileOutputStream(whitelistFile))) {
@@ -76,12 +76,12 @@ public static void beforeClass() throws IOException {
7676
}
7777
}
7878

79-
@AfterClass
79+
@AfterAll
8080
public static void afterClass() {
8181
whitelistFile.delete();
8282
}
8383

84-
@Before
84+
@BeforeEach
8585
public void setUp() {
8686
plugin = new LdapAttrPlugin();
8787
Map<String, Object> parameters = new TreeMap<>();
@@ -144,10 +144,10 @@ public void testIsAllowed() {
144144

145145
prepareRequest("009", "[email protected]", "MI6");
146146

147-
Assert.assertFalse(plugin.isAllowed(dummyRequest, makeProject("Random Project")));
148-
Assert.assertFalse(plugin.isAllowed(dummyRequest, makeProject("Project 1")));
149-
Assert.assertFalse(plugin.isAllowed(dummyRequest, makeGroup("Group 1")));
150-
Assert.assertFalse(plugin.isAllowed(dummyRequest, makeGroup("Group 2")));
147+
assertFalse(plugin.isAllowed(dummyRequest, makeProject("Random Project")));
148+
assertFalse(plugin.isAllowed(dummyRequest, makeProject("Project 1")));
149+
assertFalse(plugin.isAllowed(dummyRequest, makeGroup("Group 1")));
150+
assertFalse(plugin.isAllowed(dummyRequest, makeGroup("Group 2")));
151151

152152
prepareRequest("00A", "[email protected]", "MI6", "MI7");
153153

plugins/src/test/java/opengrok/auth/plugin/LdapFilterPluginTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package opengrok.auth.plugin;
2424

@@ -27,16 +27,17 @@
2727
import java.util.TreeSet;
2828
import opengrok.auth.entity.LdapUser;
2929
import opengrok.auth.plugin.entity.User;
30-
import org.junit.Before;
31-
import org.junit.Test;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
3232

3333
import static org.junit.Assert.assertEquals;
34+
import static org.junit.Assert.assertThrows;
3435

3536
public class LdapFilterPluginTest {
3637

3738
private LdapFilterPlugin plugin;
3839

39-
@Before
40+
@BeforeEach
4041
public void setUp() {
4142
plugin = new LdapFilterPlugin();
4243
}
@@ -103,8 +104,8 @@ public void testLoadTransforms() {
103104
plugin.loadTransforms("foo:toUpperCase,bar:toLowerCase");
104105
}
105106

106-
@Test(expected = UnsupportedOperationException.class)
107+
@Test
107108
public void testLoadTransformsNegative() {
108-
plugin.loadTransforms("foo:toUpperCase,ugly:nice");
109+
assertThrows(UnsupportedOperationException.class, () -> plugin.loadTransforms("foo:toUpperCase,ugly:nice"));
109110
}
110111
}

plugins/src/test/java/opengrok/auth/plugin/LdapServerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package opengrok.auth.plugin;
2424

2525
import opengrok.auth.plugin.ldap.LdapServer;
26-
import org.junit.Test;
26+
import org.junit.jupiter.api.Test;
2727
import org.mockito.Mockito;
2828

2929
import java.io.IOException;

plugins/src/test/java/opengrok/auth/plugin/LdapUserPluginTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
import opengrok.auth.plugin.ldap.LdapException;
3636
import opengrok.auth.plugin.ldap.LdapFacade;
3737
import opengrok.auth.plugin.util.DummyHttpServletRequestLdap;
38-
import org.junit.Before;
39-
import org.junit.Test;
38+
import org.junit.jupiter.api.BeforeEach;
39+
import org.junit.jupiter.api.Test;
4040

4141
import static opengrok.auth.plugin.LdapUserPlugin.SESSION_ATTR;
42-
import static org.junit.Assert.assertEquals;
43-
import static org.junit.Assert.assertNotNull;
42+
import static org.junit.jupiter.api.Assertions.assertEquals;
43+
import static org.junit.jupiter.api.Assertions.assertNotNull;
44+
import static org.junit.jupiter.api.Assertions.assertThrows;
4445
import static org.mockito.ArgumentMatchers.any;
4546
import static org.mockito.ArgumentMatchers.isNull;
4647
import static org.mockito.Mockito.mock;
@@ -53,7 +54,7 @@ public class LdapUserPluginTest {
5354

5455
private LdapUserPlugin plugin;
5556

56-
@Before
57+
@BeforeEach
5758
public void setUp() {
5859
plugin = new LdapUserPlugin();
5960
}
@@ -66,11 +67,11 @@ private Map<String, Object> getParamsMap() {
6667
return params;
6768
}
6869

69-
@Test(expected = NullPointerException.class)
70+
@Test
7071
public void loadTestNegative1() {
7172
Map<String, Object> params = getParamsMap();
7273
params.put("foo", "bar");
73-
plugin.load(params);
74+
assertThrows(NullPointerException.class, () -> plugin.load(params));
7475
}
7576

7677
@Test
@@ -132,11 +133,11 @@ public void testInstance() {
132133
assertEquals(request.getSession().getAttribute(SESSION_ATTR + "42"), ldapUser);
133134
}
134135

135-
@Test(expected = NumberFormatException.class)
136+
@Test
136137
public void testInvalidInstance() {
137138
Map<String, Object> params = getParamsMap();
138139
params.put(LdapUserPlugin.ATTRIBUTES, "mail");
139140
params.put(LdapUserPlugin.INSTANCE, "foobar");
140-
plugin.load(params);
141+
assertThrows(NumberFormatException.class, () -> plugin.load(params));
141142
}
142143
}

plugins/src/test/java/opengrok/auth/plugin/TruePluginTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
package opengrok.auth.plugin;
2424

2525
import opengrok.auth.plugin.entity.User;
26-
import org.junit.Before;
27-
import org.junit.Test;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2828
import org.opengrok.indexer.configuration.Group;
2929
import org.opengrok.indexer.configuration.Project;
3030
import org.opengrok.indexer.util.RandomString;
3131
import org.opengrok.indexer.web.DummyHttpServletRequest;
3232

33-
import static org.junit.Assert.assertTrue;
33+
import static org.junit.jupiter.api.Assertions.assertTrue;
3434

3535
/**
3636
* Represents a container for tests of {@link TruePlugin}.
@@ -39,7 +39,7 @@ public class TruePluginTest {
3939

4040
private TruePlugin plugin;
4141

42-
@Before
42+
@BeforeEach
4343
public void setUp() {
4444
plugin = new TruePlugin();
4545
}
@@ -61,11 +61,11 @@ public void shouldAllowRandomUserForAnyProject() {
6161

6262
Project randomProject = new Project(RandomString.generateUpper(10));
6363
boolean projectAllowed = plugin.isAllowed(req, randomProject);
64-
assertTrue("should allow rando for random project 1", projectAllowed);
64+
assertTrue(projectAllowed, "should allow rando for random project 1");
6565

6666
randomProject = new Project(RandomString.generateUpper(10));
6767
projectAllowed = plugin.isAllowed(req, randomProject);
68-
assertTrue("should allow rando for random project 2", projectAllowed);
68+
assertTrue(projectAllowed, "should allow rando for random project 2");
6969
}
7070

7171
@Test
@@ -75,10 +75,10 @@ public void shouldAllowRandomUserForAnyGroup() {
7575

7676
Group randomGroup = new Group(RandomString.generateUpper(10));
7777
boolean projectAllowed = plugin.isAllowed(req, randomGroup);
78-
assertTrue("should allow rando for random group 1", projectAllowed);
78+
assertTrue(projectAllowed, "should allow rando for random group 1");
7979

8080
randomGroup = new Group(RandomString.generateUpper(10));
8181
projectAllowed = plugin.isAllowed(req, randomGroup);
82-
assertTrue("should allow rando for random group 2", projectAllowed);
82+
assertTrue(projectAllowed, "should allow rando for random group 2");
8383
}
8484
}

plugins/src/test/java/opengrok/auth/plugin/UserPluginTest.java

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,24 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package opengrok.auth.plugin;
2424

2525
import jakarta.servlet.http.HttpServletRequest;
2626
import opengrok.auth.plugin.decoders.OSSOHeaderDecoder;
2727
import opengrok.auth.plugin.entity.User;
2828
import opengrok.auth.plugin.util.DummyHttpServletRequestUser;
29-
import org.junit.Assert;
30-
import org.junit.Before;
31-
import org.junit.Test;
29+
import org.junit.jupiter.api.BeforeEach;
30+
import org.junit.jupiter.api.Test;
3231
import org.opengrok.indexer.configuration.Group;
3332
import org.opengrok.indexer.configuration.Project;
3433

34+
import static org.junit.jupiter.api.Assertions.assertEquals;
35+
import static org.junit.jupiter.api.Assertions.assertFalse;
36+
import static org.junit.jupiter.api.Assertions.assertNull;
37+
import static org.junit.jupiter.api.Assertions.assertTrue;
38+
3539
/**
3640
*
3741
* @author Krystof Tulinger
@@ -40,43 +44,43 @@ public class UserPluginTest {
4044

4145
private UserPlugin plugin;
4246

43-
@Before
47+
@BeforeEach
4448
public void setUp() {
4549
plugin = new UserPlugin(new OSSOHeaderDecoder());
4650
}
4751

4852
@Test
4953
public void testNoUser() {
50-
Assert.assertFalse(plugin.isAllowed(new DummyHttpServletRequestUser(), new Group()));
51-
Assert.assertFalse(plugin.isAllowed(new DummyHttpServletRequestUser(), new Project()));
52-
Assert.assertFalse(plugin.isAllowed(new DummyHttpServletRequestUser(), createGroup("some group")));
53-
Assert.assertFalse(plugin.isAllowed(new DummyHttpServletRequestUser(), createProject("some project")));
54+
assertFalse(plugin.isAllowed(new DummyHttpServletRequestUser(), new Group()));
55+
assertFalse(plugin.isAllowed(new DummyHttpServletRequestUser(), new Project()));
56+
assertFalse(plugin.isAllowed(new DummyHttpServletRequestUser(), createGroup("some group")));
57+
assertFalse(plugin.isAllowed(new DummyHttpServletRequestUser(), createProject("some project")));
5458
}
5559

5660
@Test
5761
public void testUser() {
5862
HttpServletRequest req;
59-
Assert.assertTrue(plugin.isAllowed(req = createRequest("007"), new Group()));
60-
Assert.assertEquals("007", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
61-
Assert.assertTrue(plugin.isAllowed(req = createRequest("008"), new Project()));
62-
Assert.assertEquals("008", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
63-
Assert.assertTrue(plugin.isAllowed(req = createRequest("009"), createGroup("some group")));
64-
Assert.assertEquals("009", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
65-
Assert.assertTrue(plugin.isAllowed(req = createRequest("00A"), createProject("some project")));
66-
Assert.assertEquals("00A", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
63+
assertTrue(plugin.isAllowed(req = createRequest("007"), new Group()));
64+
assertEquals("007", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
65+
assertTrue(plugin.isAllowed(req = createRequest("008"), new Project()));
66+
assertEquals("008", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
67+
assertTrue(plugin.isAllowed(req = createRequest("009"), createGroup("some group")));
68+
assertEquals("009", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
69+
assertTrue(plugin.isAllowed(req = createRequest("00A"), createProject("some project")));
70+
assertEquals("00A", ((User) req.getAttribute(UserPlugin.REQUEST_ATTR)).getUsername());
6771
}
6872

6973
@Test
7074
public void testTimeoutedUser() {
7175
HttpServletRequest req;
72-
Assert.assertFalse(plugin.isAllowed(req = createRequest("007", true), new Group()));
73-
Assert.assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
74-
Assert.assertFalse(plugin.isAllowed(req = createRequest("008", true), new Project()));
75-
Assert.assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
76-
Assert.assertFalse(plugin.isAllowed(req = createRequest("009", true), createGroup("some group")));
77-
Assert.assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
78-
Assert.assertFalse(plugin.isAllowed(req = createRequest("00A", true), createProject("some project")));
79-
Assert.assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
76+
assertFalse(plugin.isAllowed(req = createRequest("007", true), new Group()));
77+
assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
78+
assertFalse(plugin.isAllowed(req = createRequest("008", true), new Project()));
79+
assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
80+
assertFalse(plugin.isAllowed(req = createRequest("009", true), createGroup("some group")));
81+
assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
82+
assertFalse(plugin.isAllowed(req = createRequest("00A", true), createProject("some project")));
83+
assertNull(req.getAttribute(UserPlugin.REQUEST_ATTR));
8084
}
8185

8286
protected HttpServletRequest createRequest(String email) {

0 commit comments

Comments
 (0)