Posted by
danwatford on
Jan 14, 2021; 5:10pm
URL: http://ofbiz.116.s1.nabble.com/ofbiz-framework-branch-trunk-updated-Improved-Removed-deprecated-ExpectedException-none-from-tests-tp4763799.html
This is an automated email from the ASF dual-hosted git repository.
danwatford pushed a commit to branch trunk
in repository
https://gitbox.apache.org/repos/asf/ofbiz-framework.gitThe following commit(s) were added to refs/heads/trunk by this push:
new 7830328 Improved: Removed deprecated ExpectedException.none from tests
7830328 is described below
commit 7830328bb4d108b2427c9e1830876030fa0386eb
Author: Daniel Watford <
[hidden email]>
AuthorDate: Thu Jan 14 17:07:40 2021 +0000
Improved: Removed deprecated ExpectedException.none from tests
(OFBIZ-12137)
Prevents logging of deprecation warnings during the build.
---
.../apache/ofbiz/entity/DelegatorUnitTests.java | 28 +++++------
.../ofbiz/base/start/OfbizStartupUnitTests.java | 57 ++++++++++------------
2 files changed, 40 insertions(+), 45 deletions(-)
diff --git a/framework/entity/src/test/java/org/apache/ofbiz/entity/DelegatorUnitTests.java b/framework/entity/src/test/java/org/apache/ofbiz/entity/DelegatorUnitTests.java
index 27ebf372..5a873fe 100644
--- a/framework/entity/src/test/java/org/apache/ofbiz/entity/DelegatorUnitTests.java
+++ b/framework/entity/src/test/java/org/apache/ofbiz/entity/DelegatorUnitTests.java
@@ -18,26 +18,24 @@
*******************************************************************************/
package org.apache.ofbiz.entity;
+import org.apache.ofbiz.base.util.Debug;
+import org.hamcrest.MatcherAssert;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import org.apache.ofbiz.base.util.Debug;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
public class DelegatorUnitTests {
private boolean logErrorOn;
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Before
public void initialize() {
System.setProperty("ofbiz.home", System.getProperty("user.dir"));
@@ -52,10 +50,11 @@ public class DelegatorUnitTests {
}
@Test
- public void delegatorCreationUsingConstructorFailsIfConfigurationIsMissing() throws GenericEntityException {
- expectedException.expect(GenericEntityException.class);
- expectedException.expectMessage("No configuration found for delegator");
- new GenericDelegator("delegatorNameWithNoConfiguration");
+ public void delegatorCreationUsingConstructorFailsIfConfigurationIsMissing() {
+ GenericEntityException gee = assertThrows(GenericEntityException.class, () ->
+ new GenericDelegator("delegatorNameWithNoConfiguration"));
+
+ MatcherAssert.assertThat(gee.getMessage(), containsString("No configuration found for delegator"));
}
@Test
@@ -102,5 +101,4 @@ public class DelegatorUnitTests {
Delegator delegator = df.getInstance("delegatorNameWithNoConfiguration");
assertNull(delegator);
}
-
}
diff --git a/framework/start/src/test/java/org/apache/ofbiz/base/start/OfbizStartupUnitTests.java b/framework/start/src/test/java/org/apache/ofbiz/base/start/OfbizStartupUnitTests.java
index 0371428..0cde542 100644
--- a/framework/start/src/test/java/org/apache/ofbiz/base/start/OfbizStartupUnitTests.java
+++ b/framework/start/src/test/java/org/apache/ofbiz/base/start/OfbizStartupUnitTests.java
@@ -19,60 +19,57 @@
package org.apache.ofbiz.base.start;
-import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThrows;
import java.util.List;
-import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
public class OfbizStartupUnitTests {
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Test
- public void commandParserDoesNotAcceptMoreThanOneCommand() throws StartupException {
- expectedException.expectMessage("an option from this group has already been selected");
-
- StartupCommandUtil.parseOfbizCommands(new String[]{"--help", "--status"});
+ public void commandParserDoesNotAcceptMoreThanOneCommand() {
+ Exception e = assertThrows(Exception.class, () ->
+ StartupCommandUtil.parseOfbizCommands(new String[]{"--help", "--status"}));
+ assertThat(e.getMessage(), containsString("an option from this group has already been selected"));
}
@Test
- public void commandParserDoesNotAcceptPortoffsetWithoutArgument() throws StartupException {
- expectedException.expectMessage("Missing argument for option");
-
- StartupCommandUtil.parseOfbizCommands(new String[]{"--portoffset"});
+ public void commandParserDoesNotAcceptPortoffsetWithoutArgument() {
+ Exception e = assertThrows(Exception.class, () ->
+ StartupCommandUtil.parseOfbizCommands(new String[]{"--portoffset"}));
+ assertThat(e.getMessage(), containsString("Missing argument for option"));
}
@Test
- public void commandParserDoesNotAcceptPortoffsetWithoutPositiveInteger() throws StartupException {
- expectedException.expectMessage("you can only pass positive integers");
-
- StartupCommandUtil.parseOfbizCommands(new String[]{"--portoffset", "ThisMustBeInteger54321"});
+ public void commandParserDoesNotAcceptPortoffsetWithoutPositiveInteger() {
+ Exception e = assertThrows(Exception.class, () ->
+ StartupCommandUtil.parseOfbizCommands(new String[]{"--portoffset", "ThisMustBeInteger54321"}));
+ assertThat(e.getMessage(), containsString("you can only pass positive integers"));
}
@Test
- public void commandParserDoesNotAcceptArgumentForStatus() throws StartupException {
- expectedException.expectMessage("unrecognized options / properties");
-
- StartupCommandUtil.parseOfbizCommands(new String[]{"--status", "thisArgNotAllowed"});
+ public void commandParserDoesNotAcceptArgumentForStatus() {
+ Exception e = assertThrows(Exception.class, () ->
+ StartupCommandUtil.parseOfbizCommands(new String[]{"--status", "thisArgNotAllowed"}));
+ assertThat(e.getMessage(), containsString("unrecognized options / properties"));
}
@Test
- public void commandParserDoesNotAcceptArgumentForStart() throws StartupException {
- expectedException.expectMessage("unrecognized options / properties");
-
- StartupCommandUtil.parseOfbizCommands(new String[]{"--start", "thisArgNotAllowed"});
+ public void commandParserDoesNotAcceptArgumentForStart() {
+ Exception e = assertThrows(Exception.class, () ->
+ StartupCommandUtil.parseOfbizCommands(new String[]{"--start", "thisArgNotAllowed"}));
+ assertThat(e.getMessage(), containsString("unrecognized options / properties"));
}
@Test
- public void commandParserDoesNotAcceptArgumentForShutdown() throws StartupException {
- expectedException.expectMessage("unrecognized options / properties");
-
- StartupCommandUtil.parseOfbizCommands(new String[]{"--shutdown", "thisArgNotAllowed"});
+ public void commandParserDoesNotAcceptArgumentForShutdown() {
+ Exception e = assertThrows(Exception.class, () ->
+ StartupCommandUtil.parseOfbizCommands(new String[]{"--shutdown", "thisArgNotAllowed"}));
+ assertThat(e.getMessage(), containsString("unrecognized options / properties"));
}
@Test