You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/01/17 12:37:30 UTC
[isis] branch master updated: ISIS-2158: test and fix bookmark
parsing
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 1518308 ISIS-2158: test and fix bookmark parsing
1518308 is described below
commit 1518308e6845b26d6a695e45b7f9179daae35beb
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri Jan 17 13:37:18 2020 +0100
ISIS-2158: test and fix bookmark parsing
---
.../isis/applib/services/bookmark/Bookmark.java | 5 +-
.../applib/services/bookmark/BookmarkTest.java | 64 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 1 deletion(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/bookmark/Bookmark.java b/api/applib/src/main/java/org/apache/isis/applib/services/bookmark/Bookmark.java
index 447a196..c346be5 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/bookmark/Bookmark.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/bookmark/Bookmark.java
@@ -62,9 +62,12 @@ public class Bookmark implements Serializable {
}
val tokenizer = new StringTokenizer(str, SEPARATOR);
int tokenCount = tokenizer.countTokens();
- if(tokenCount>1) {
+ if(tokenCount==2) {
return Optional.of(Bookmark.of(tokenizer.nextToken(), tokenizer.nextToken()));
}
+ if(tokenCount>2) {
+ return Optional.of(Bookmark.of(tokenizer.nextToken(), tokenizer.nextToken("").substring(1)));
+ }
return Optional.empty();
}
diff --git a/api/applib/src/test/java/org/apache/isis/applib/services/bookmark/BookmarkTest.java b/api/applib/src/test/java/org/apache/isis/applib/services/bookmark/BookmarkTest.java
new file mode 100644
index 0000000..a48bb45
--- /dev/null
+++ b/api/applib/src/test/java/org/apache/isis/applib/services/bookmark/BookmarkTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.applib.services.bookmark;
+
+import java.util.Optional;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import lombok.val;
+
+class BookmarkTest {
+
+ @Test
+ void shouldParse_whenExactly2Token() {
+
+ val bookmark = Bookmark.parse("a:b").get();
+
+ assertEquals("a", bookmark.getObjectType());
+ assertEquals("b", bookmark.getIdentifier());
+
+ }
+
+ @Test
+ void shouldNotParse_whenNotAtLeast2Token() {
+
+ assertEquals(Optional.empty(), Bookmark.parse(null));
+ assertEquals(Optional.empty(), Bookmark.parse(""));
+ assertEquals(Optional.empty(), Bookmark.parse("a"));
+ assertEquals(Optional.empty(), Bookmark.parse("a:"));
+ assertEquals(Optional.empty(), Bookmark.parse(":"));
+ assertEquals(Optional.empty(), Bookmark.parse(":b"));
+
+ }
+
+
+ @Test
+ void shouldParse_whenMoreThan2Token() {
+
+ val bookmark = Bookmark.parse("a:b:c").get();
+
+ assertEquals("a", bookmark.getObjectType());
+ assertEquals("b:c", bookmark.getIdentifier());
+
+ }
+
+}