NPipeSocketAddress extends SocketAddress { @Nonnull public static NPipeSocketAddress fromPath(@Nonnull Path pipe) { if (!PIPE_NAME_PTN.matcher(pipe.toString()).matches()) { throw new IllegalArgumentException("The provided path does not looks like a pipe name: " + pipe); } return new NPipeSocketAddress(pipe); } NPipeSocketAddress(Path pipe); @Nonnull static NPipeSocketAddress fromPath(@Nonnull Path pipe); @Nonnull Path getPipe();  }
@Test public void illegalConstructorArg() { Arrays.asList( "C:\\docker_engine", "\\tmp\\docker_engine", "\\docker_engine", "\\\\host\\share\\docker_engine", "\\.\\pipe\\docker_engine", "\\\\.\\pipe\\docker_engine\\" ).forEach(location -> assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> NPipeSocketAddress.fromPath(Paths.get(location))) ); assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> NPipeSocketAddress.fromPath(null)); }
@Test public void legalConstructorArg() { NPipeSocketAddress.fromPath(Paths.get("\\\\.\\pipe\\docker_engine")); NPipeSocketAddress.fromPath(Paths.get("\\\\.\\pipe\\docker_engine\\subdir")); NPipeSocketAddress.fromPath(Paths.get("\\\\.\\pipe\\docker_engine\\subdir1\\subdir2")); }