Skip to content

Commit

Permalink
#31 - impproved failure messages
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoltz committed Aug 13, 2018
1 parent 01acf68 commit 2382335
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 7 deletions.
32 changes: 32 additions & 0 deletions src/main/java/org/opengis/cite/wfs30/EtsAssert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.opengis.cite.wfs30;

/**
* Provides a set of custom assertion methods.
*
* @author <a href="mailto:[email protected]">Lyn Goltz </a>
*/
public class EtsAssert {

/**
* @param valueToAssert
* the boolean to assert to be <code>true</code>
* @param failureMsg
* the message to throw in case of a failure, should not be <code>null</code>
*/
public static void assertTrue( boolean valueToAssert, String failureMsg ) {
if ( !valueToAssert )
throw new AssertionError( failureMsg );
}

/**
* @param valueToAssert
* the boolean to assert to be <code>false</code>
* @param failureMsg
* the message to throw in case of a failure, should not be <code>null</code>
*/
public static void assertFalse( boolean valueToAssert, String failureMsg ) {
if ( valueToAssert )
throw new AssertionError( failureMsg );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static io.restassured.http.ContentType.JSON;
import static io.restassured.http.Method.GET;
import static org.testng.Assert.assertTrue;
import static org.opengis.cite.wfs30.EtsAssert.assertTrue;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void landingPageValidation() {
&& linkTypes.contains( "data" );
assertTrue( expectedLinkTypesExists,
"The landing page must include at least links with relation type 'service', 'conformance' and 'data', but contains "
+ linkTypes );
+ String.join( ", ", linkTypes ) );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import static io.restassured.http.ContentType.JSON;
import static io.restassured.http.Method.GET;
import static org.opengis.cite.wfs30.EtsAssert.assertTrue;
import static org.opengis.cite.wfs30.SuiteAttribute.API_MODEL;
import static org.opengis.cite.wfs30.WFS3.OPEN_API_MIME_TYPE;
import static org.testng.Assert.assertTrue;

import java.net.MalformedURLException;
import java.net.URL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.restassured.http.ContentType.JSON;
import static io.restassured.http.Method.GET;
import static org.opengis.cite.wfs30.EtsAssert.assertTrue;
import static org.opengis.cite.wfs30.SuiteAttribute.API_MODEL;
import static org.opengis.cite.wfs30.WFS3.PATH.COLLECTIONS;
import static org.opengis.cite.wfs30.openapi3.OpenApiUtils.retrieveTestPoints;
Expand All @@ -12,7 +13,6 @@
import static org.opengis.cite.wfs30.util.JsonUtils.linkIncludesRelAndType;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opengis.cite.wfs30.collections;

import static io.restassured.http.Method.GET;
import static org.opengis.cite.wfs30.EtsAssert.assertTrue;
import static org.opengis.cite.wfs30.SuiteAttribute.API_MODEL;
import static org.opengis.cite.wfs30.WFS3.GEOJSON_MIME_TYPE;
import static org.opengis.cite.wfs30.WFS3.PATH.COLLECTIONS;
Expand All @@ -11,7 +12,6 @@
import static org.opengis.cite.wfs30.util.JsonUtils.findUnsupportedTypes;
import static org.opengis.cite.wfs30.util.JsonUtils.linkIncludesRelAndType;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.opengis.cite.wfs30.collections;

import static io.restassured.http.Method.GET;
import static org.opengis.cite.wfs30.EtsAssert.assertFalse;
import static org.opengis.cite.wfs30.EtsAssert.assertTrue;
import static org.opengis.cite.wfs30.SuiteAttribute.API_MODEL;
import static org.opengis.cite.wfs30.WFS3.GEOJSON_MIME_TYPE;
import static org.opengis.cite.wfs30.WFS3.PATH.COLLECTIONS;
Expand All @@ -18,9 +20,7 @@
import static org.opengis.cite.wfs30.util.JsonUtils.parseSpatialExtent;
import static org.opengis.cite.wfs30.util.JsonUtils.parseTemporalExtent;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;

import java.net.URISyntaxException;
import java.time.Duration;
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/EtsAssertTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import org.junit.Test;
import org.opengis.cite.wfs30.EtsAssert;

/**
* @author <a href="mailto:[email protected]">Lyn Goltz </a>
*/
public class EtsAssertTest {

@Test
public void testAssertTrue() {
EtsAssert.assertTrue( true, "OK" );
}

@Test
public void testAssertFalse() {
EtsAssert.assertFalse( false, "OK" );
}

@Test(expected = AssertionError.class)
public void testAssertTrue_false() {
EtsAssert.assertTrue( false, "FAIlURE" );
}

@Test(expected = AssertionError.class)
public void testAssertFalse_true() {
EtsAssert.assertFalse( true, "FAIlURE" );

}

}

0 comments on commit 2382335

Please sign in to comment.