Bookmark implements Serializable { public static Optional<Bookmark> parse(@Nullable String str) { if(str==null) { return Optional.empty(); } val tokenizer = new StringTokenizer(str, SEPARATOR); int tokenCount = tokenizer.countTokens(); 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(); }  static Bookmark of(String objectType, String identifier); static Optional<Bookmark> parse(@Nullable String str); OidDto toOidDto(); static Bookmark from(@NonNull OidDto oidDto); @Override String toString(); Bookmark withHintId(@NonNull String hintId); String toStringUsingIdentifier(String id);  }
@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()); }