@Test public void testReaderMultipleIpsSame() throws IOException{ BufferedReader br = mock(BufferedReader.class); when(br.readLine()).thenReturn("10.18.85.186","10.18.85.186",(String)null); List<String> returnVal = GetLocalIP.getIPFromInputStream(br); assertNotNull(returnVal); assertFalse(returnVal.isEmpty()); assertEquals("10.18.85.186", returnVal.get(0)); }
protected static List<String> getIPFromInputStream(BufferedReader reader) { if (reader != null) { Set<String> allLines = new LinkedHashSet<>(); String line = null; try { while ((line = reader.readLine()) != null) { Matcher matcher = kIPPattern.matcher(line); if (matcher.matches()) { allLines.add(line); } } } catch (IOException e) { e.printStackTrace(); } return allLines.stream().collect(Collectors.toList()); } return Collections.emptyList(); }
GetLocalIP { protected static List<String> getIPFromInputStream(BufferedReader reader) { if (reader != null) { Set<String> allLines = new LinkedHashSet<>(); String line = null; try { while ((line = reader.readLine()) != null) { Matcher matcher = kIPPattern.matcher(line); if (matcher.matches()) { allLines.add(line); } } } catch (IOException e) { e.printStackTrace(); } return allLines.stream().collect(Collectors.toList()); } return Collections.emptyList(); } }
GetLocalIP { protected static List<String> getIPFromInputStream(BufferedReader reader) { if (reader != null) { Set<String> allLines = new LinkedHashSet<>(); String line = null; try { while ((line = reader.readLine()) != null) { Matcher matcher = kIPPattern.matcher(line); if (matcher.matches()) { allLines.add(line); } } } catch (IOException e) { e.printStackTrace(); } return allLines.stream().collect(Collectors.toList()); } return Collections.emptyList(); } private  GetLocalIP(); }
GetLocalIP { protected static List<String> getIPFromInputStream(BufferedReader reader) { if (reader != null) { Set<String> allLines = new LinkedHashSet<>(); String line = null; try { while ((line = reader.readLine()) != null) { Matcher matcher = kIPPattern.matcher(line); if (matcher.matches()) { allLines.add(line); } } } catch (IOException e) { e.printStackTrace(); } return allLines.stream().collect(Collectors.toList()); } return Collections.emptyList(); } private  GetLocalIP(); static Optional<String> getIp(); static List<String> getAllIps(); static void main(String[] pArgs); }
GetLocalIP { protected static List<String> getIPFromInputStream(BufferedReader reader) { if (reader != null) { Set<String> allLines = new LinkedHashSet<>(); String line = null; try { while ((line = reader.readLine()) != null) { Matcher matcher = kIPPattern.matcher(line); if (matcher.matches()) { allLines.add(line); } } } catch (IOException e) { e.printStackTrace(); } return allLines.stream().collect(Collectors.toList()); } return Collections.emptyList(); } private  GetLocalIP(); static Optional<String> getIp(); static List<String> getAllIps(); static void main(String[] pArgs);  }