Skip to content

Commit

Permalink
#186 - use default creator if none provided
Browse files Browse the repository at this point in the history
  • Loading branch information
r-follador committed Jan 9, 2025
1 parent 276ea08 commit 699eea6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
22 changes: 16 additions & 6 deletions jpx/src/main/java/io/jenetics/jpx/GPX.java
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ public static Version of(final String version) {
*
* @param creator the name or URL of the software that created your GPX
* document. This allows others to inform the creator of a GPX
* instance document that fails to validate.
* instance document that fails to validate. If the {@code creator}
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
* is used instead.
* @param version the GPX version
* @param metadata the metadata about the GPS file
* @param wayPoints the way-points
Expand All @@ -322,7 +324,7 @@ private GPX(
final Document extensions
) {
_version = requireNonNull(version);
_creator = creator;
_creator = creator != null ? creator : _CREATOR;
_metadata = metadata;
_wayPoints = copyOf(wayPoints);
_routes = copyOf(routes);
Expand Down Expand Up @@ -1701,7 +1703,9 @@ public static Writer of(final Indent indent) {
*
* @param creator the name or URL of the software that created your GPX
* document. This allows others to inform the creator of a GPX
* instance document that fails to validate.
* instance document that fails to validate. If the {@code creator}
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
* is used instead.
* @param version the GPX version
* @param metadata the metadata about the GPS file
* @param wayPoints the way-points
Expand Down Expand Up @@ -1737,7 +1741,9 @@ public static GPX of(
*
* @param creator the name or URL of the software that created your GPX
* document. This allows others to inform the creator of a GPX
* instance document that fails to validate.
* instance document that fails to validate. If the {@code creator}
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
* is used instead.
* @param metadata the metadata about the GPS file
* @param wayPoints the way-points
* @param routes the routes
Expand Down Expand Up @@ -1771,7 +1777,9 @@ public static GPX of(
*
* @param creator the name or URL of the software that created your GPX
* document. This allows others to inform the creator of a GPX
* instance document that fails to validate.
* instance document that fails to validate. If the {@code creator}
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
* is used instead.
* @param metadata the metadata about the GPS file
* @param wayPoints the way-points
* @param routes the routes
Expand Down Expand Up @@ -1805,7 +1813,9 @@ public static GPX of(
*
* @param creator the name or URL of the software that created your GPX
* document. This allows others to inform the creator of a GPX
* instance document that fails to validate.
* instance document that fails to validate. If the {@code creator}
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
* is used instead.
* @param version the GPX version
* @param metadata the metadata about the GPS file
* @param wayPoints the way-points
Expand Down
16 changes: 15 additions & 1 deletion jpx/src/test/java/io/jenetics/jpx/GPXTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ public void issue186_MissingCreator() throws IOException {
}

assertThat(gpx_lenient.getVersion()).isEqualTo("1.1");
assertThat(gpx_lenient.getCreator()).isNull();
assertThat(gpx_lenient.getCreator()).isEqualTo("JPX - https://github.com/jenetics/jpx");
assertThat(gpx_lenient.getTracks()).hasSize(1);
assertThat(gpx_lenient.getTracks().get(0).getSegments()).hasSize(1);
assertThat(gpx_lenient.getTracks().get(0).getSegments().get(0)).hasSize(9);
Expand All @@ -983,8 +983,22 @@ public void issue186_MissingCreator() throws IOException {
} catch (Exception e) {
Assert.fail("Unexpected exception was thrown: " + e);
}
}

@Test
public void issue186_NullCreator() throws IOException {
Random random = new Random();
GPX createGPX = GPX.of(
Version.V11,
null,
random.nextBoolean() ? MetadataTest.nextMetadata(random) : null,
random.nextBoolean() ? WayPointTest.nextWayPoints(random) : null,
random.nextBoolean() ? RouteTest.nextRoutes(random) : null,
random.nextBoolean() ? TrackTest.nextTracks(random) : null,
random.nextBoolean() ? doc() : null
);

assertThat(createGPX.getCreator()).isEqualTo("JPX - https://github.com/jenetics/jpx");
}

}

0 comments on commit 699eea6

Please sign in to comment.