AuthorizationTree implements AuthorizationInfo { @Override public Optional<List<AuthorizationNode>> getAuthorizationLineage(String blockchainAddress) { Optional<List<AuthorizationNode>> strandAsList = tree.getStrands() .map(strand -> strand.collect(Collectors.toList())) .filter(strand -> strand.stream().anyMatch(node -> node.getAddress().equals(blockchainAddress))) .findFirst(); if (strandAsList.isPresent()) { final List<AuthorizationNode> result = new ArrayList<>(); for (AuthorizationNode node : strandAsList.get()) { result.add(node); if (node.getAddress().equals(blockchainAddress)) break; } return Optional.of(result); } else { return Optional.empty(); } } AuthorizationTree(List<AuthorizationElement> allAuthorizationElements); @Override boolean isAuthorized(String blockchainAddress); @Override Optional<String> getServiceOwnerBlockchainAddress(); @Override Optional<String> getRealWorldIdentity(String blockchainAddress); @Override Optional<List<AuthorizationNode>> getAuthorizationLineage(String blockchainAddress); @Override String toString();  }
@Test public void getLineage() { final Optional<List<AuthorizationNode>> lineage = this.authorizationTree.getAuthorizationLineage("0x3333"); assertTrue(lineage.isPresent()); assertEquals(3, lineage.get().size()); assertEquals("0x3333", ((AuthorizationNode) lineage.get().toArray()[lineage.get().size() - 1]).getAddress()); assertEquals("0x2222", ((AuthorizationNode) lineage.get().toArray()[lineage.get().size() - 2]).getAddress()); assertEquals("0x1111", ((AuthorizationNode) lineage.get().toArray()[lineage.get().size() - 3]).getAddress()); }