### Question:
LoopbackLinkFactory implements LinkFactory { public Link<?> constructLink( final Supplier<InterledgerAddress> operatorAddressSupplier, final LinkSettings linkSettings ) { Objects.requireNonNull(operatorAddressSupplier, "operatorAddressSupplier must not be null"); Objects.requireNonNull(linkSettings, "linkSettings must not be null"); if (!this.supports(linkSettings.getLinkType())) { throw new LinkException( String.format("LinkType not supported by this factory. linkType=%s", linkSettings.getLinkType()), LinkId.of("n/a") ); } return new LoopbackLink(operatorAddressSupplier, linkSettings, packetRejector); } LoopbackLinkFactory(final PacketRejector packetRejector); Link<?> constructLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier, final LinkSettings linkSettings
  ); @Override boolean supports(LinkType linkType);  }### Answer:
@Test(expected = NullPointerException.class) public void constructLinkWithNullOperator() { try { loopbackLinkFactory.constructLink(null, linkSettingsMock); fail(); } catch (NullPointerException e) { assertThat(e.getMessage()).isEqualTo("operatorAddressSupplier must not be null"); throw e; } }
@Test(expected = NullPointerException.class) public void constructLinkWithNullLinkSettings() { try { loopbackLinkFactory.constructLink(() -> OPERATOR_ADDRESS, null); fail(); } catch (NullPointerException e) { assertThat(e.getMessage()).isEqualTo("linkSettings must not be null"); throw e; } }
@Test(expected = LinkException.class) public void constructLinkWithUnsupportedLinkType() { try { LinkSettings linkSettings = LinkSettings.builder() .linkType(LinkType.of("foo")) .build(); loopbackLinkFactory.constructLink(() -> OPERATOR_ADDRESS, linkSettings); fail(); } catch (NullPointerException e) { assertThat(e.getMessage()).isEqualTo("LinkType not supported by this factory. linkType=LinkType(FOO)"); throw e; } }
@Test public void constructLink() { LinkSettings linkSettings = LinkSettings.builder() .linkType(LoopbackLink.LINK_TYPE) .build(); Link<?> link = loopbackLinkFactory.constructLink(() -> OPERATOR_ADDRESS, linkSettings); link.setLinkId(linkId); assertThat(link.getLinkId()).isEqualTo(linkId); }