Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improved: Removed deprecated ExpectedException.none from tests
(OFBIZ-12137)

Prevents logging of deprecation warnings during the build.
  • Loading branch information
danwatford committed Jan 14, 2021
1 parent 9acee84 commit 7830328
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 45 deletions.
Expand Up @@ -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"));
Expand All @@ -52,10 +50,11 @@ public void restore() {
}

@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
Expand Down Expand Up @@ -102,5 +101,4 @@ public void delegatorCreationUsingFactoryReturnsNullIfConfigurationIsMissing() t
Delegator delegator = df.getInstance("delegatorNameWithNoConfiguration");
assertNull(delegator);
}

}
Expand Up @@ -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
Expand Down

0 comments on commit 7830328

Please sign in to comment.