Skip to content

Commit 699eea6

Browse files
committed
#186 - use default creator if none provided
1 parent 276ea08 commit 699eea6

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

jpx/src/main/java/io/jenetics/jpx/GPX.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ public static Version of(final String version) {
302302
*
303303
* @param creator the name or URL of the software that created your GPX
304304
* document. This allows others to inform the creator of a GPX
305-
* instance document that fails to validate.
305+
* instance document that fails to validate. If the {@code creator}
306+
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
307+
* is used instead.
306308
* @param version the GPX version
307309
* @param metadata the metadata about the GPS file
308310
* @param wayPoints the way-points
@@ -322,7 +324,7 @@ private GPX(
322324
final Document extensions
323325
) {
324326
_version = requireNonNull(version);
325-
_creator = creator;
327+
_creator = creator != null ? creator : _CREATOR;
326328
_metadata = metadata;
327329
_wayPoints = copyOf(wayPoints);
328330
_routes = copyOf(routes);
@@ -1701,7 +1703,9 @@ public static Writer of(final Indent indent) {
17011703
*
17021704
* @param creator the name or URL of the software that created your GPX
17031705
* document. This allows others to inform the creator of a GPX
1704-
* instance document that fails to validate.
1706+
* instance document that fails to validate. If the {@code creator}
1707+
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
1708+
* is used instead.
17051709
* @param version the GPX version
17061710
* @param metadata the metadata about the GPS file
17071711
* @param wayPoints the way-points
@@ -1737,7 +1741,9 @@ public static GPX of(
17371741
*
17381742
* @param creator the name or URL of the software that created your GPX
17391743
* document. This allows others to inform the creator of a GPX
1740-
* instance document that fails to validate.
1744+
* instance document that fails to validate. If the {@code creator}
1745+
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
1746+
* is used instead.
17411747
* @param metadata the metadata about the GPS file
17421748
* @param wayPoints the way-points
17431749
* @param routes the routes
@@ -1771,7 +1777,9 @@ public static GPX of(
17711777
*
17721778
* @param creator the name or URL of the software that created your GPX
17731779
* document. This allows others to inform the creator of a GPX
1774-
* instance document that fails to validate.
1780+
* instance document that fails to validate. If the {@code creator}
1781+
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
1782+
* is used instead.
17751783
* @param metadata the metadata about the GPS file
17761784
* @param wayPoints the way-points
17771785
* @param routes the routes
@@ -1805,7 +1813,9 @@ public static GPX of(
18051813
*
18061814
* @param creator the name or URL of the software that created your GPX
18071815
* document. This allows others to inform the creator of a GPX
1808-
* instance document that fails to validate.
1816+
* instance document that fails to validate. If the {@code creator}
1817+
* is {@code null}, {@code "JPX - https://github.com/jenetics/jpx"}
1818+
* is used instead.
18091819
* @param version the GPX version
18101820
* @param metadata the metadata about the GPS file
18111821
* @param wayPoints the way-points

jpx/src/test/java/io/jenetics/jpx/GPXTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ public void issue186_MissingCreator() throws IOException {
969969
}
970970

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

988+
@Test
989+
public void issue186_NullCreator() throws IOException {
990+
Random random = new Random();
991+
GPX createGPX = GPX.of(
992+
Version.V11,
993+
null,
994+
random.nextBoolean() ? MetadataTest.nextMetadata(random) : null,
995+
random.nextBoolean() ? WayPointTest.nextWayPoints(random) : null,
996+
random.nextBoolean() ? RouteTest.nextRoutes(random) : null,
997+
random.nextBoolean() ? TrackTest.nextTracks(random) : null,
998+
random.nextBoolean() ? doc() : null
999+
);
9871000

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

9901004
}

0 commit comments

Comments
 (0)