@Test public void testDetectOsWithAllDetectorsFailed() { doReturn(false).when(osDetectorHelperService).foundOperatingSystem(any(OperatingSystemDetails.class)); doReturn(new OperatingSystemDetails()).when(localOsDetectorService).detectOs(any(OsDetectorInputs.class)); doReturn(new OperatingSystemDetails()).when(sshOsDetectorService).detectOs(any(OsDetectorInputs.class)); doReturn(new OperatingSystemDetails()).when(powershellOsDetectorService).detectOs(any(OsDetectorInputs.class)); doReturn(new OperatingSystemDetails()).when(nmapOsDetectorService).detectOs(any(OsDetectorInputs.class)); OperatingSystemDetails actualOsDetails = operatingSystemDetectorService.detectOs(new OsDetectorInputs.Builder().build()); assertEquals("", actualOsDetails.getName()); assertEquals("", actualOsDetails.getVersion()); assertEquals("", actualOsDetails.getFamily()); assertEquals("", actualOsDetails.getArchitecture()); }
public OperatingSystemDetails detectOs(OsDetectorInputs osDetectorInputs) { OperatingSystemDetails localOsSystemDetails = localOsDetectorService.detectOs(osDetectorInputs); if (osDetectorHelperService.foundOperatingSystem(localOsSystemDetails)) { return localOsSystemDetails; } OperatingSystemDetails sshOsSystemDetails = sshOsDetectorService.detectOs(osDetectorInputs); sshOsSystemDetails.collectOsCommandOutputs(localOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(sshOsSystemDetails)) { return sshOsSystemDetails; } OperatingSystemDetails powershellOsSystemDetails = powershellOsDetectorService.detectOs(osDetectorInputs); powershellOsSystemDetails.collectOsCommandOutputs(sshOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(powershellOsSystemDetails)) { return powershellOsSystemDetails; } OperatingSystemDetails nmapOsSystemDetails = nmapOsDetectorService.detectOs(osDetectorInputs); nmapOsSystemDetails.collectOsCommandOutputs(powershellOsSystemDetails); return nmapOsSystemDetails; }
OperatingSystemDetectorService implements OperatingSystemDetector { public OperatingSystemDetails detectOs(OsDetectorInputs osDetectorInputs) { OperatingSystemDetails localOsSystemDetails = localOsDetectorService.detectOs(osDetectorInputs); if (osDetectorHelperService.foundOperatingSystem(localOsSystemDetails)) { return localOsSystemDetails; } OperatingSystemDetails sshOsSystemDetails = sshOsDetectorService.detectOs(osDetectorInputs); sshOsSystemDetails.collectOsCommandOutputs(localOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(sshOsSystemDetails)) { return sshOsSystemDetails; } OperatingSystemDetails powershellOsSystemDetails = powershellOsDetectorService.detectOs(osDetectorInputs); powershellOsSystemDetails.collectOsCommandOutputs(sshOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(powershellOsSystemDetails)) { return powershellOsSystemDetails; } OperatingSystemDetails nmapOsSystemDetails = nmapOsDetectorService.detectOs(osDetectorInputs); nmapOsSystemDetails.collectOsCommandOutputs(powershellOsSystemDetails); return nmapOsSystemDetails; } }
OperatingSystemDetectorService implements OperatingSystemDetector { public OperatingSystemDetails detectOs(OsDetectorInputs osDetectorInputs) { OperatingSystemDetails localOsSystemDetails = localOsDetectorService.detectOs(osDetectorInputs); if (osDetectorHelperService.foundOperatingSystem(localOsSystemDetails)) { return localOsSystemDetails; } OperatingSystemDetails sshOsSystemDetails = sshOsDetectorService.detectOs(osDetectorInputs); sshOsSystemDetails.collectOsCommandOutputs(localOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(sshOsSystemDetails)) { return sshOsSystemDetails; } OperatingSystemDetails powershellOsSystemDetails = powershellOsDetectorService.detectOs(osDetectorInputs); powershellOsSystemDetails.collectOsCommandOutputs(sshOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(powershellOsSystemDetails)) { return powershellOsSystemDetails; } OperatingSystemDetails nmapOsSystemDetails = nmapOsDetectorService.detectOs(osDetectorInputs); nmapOsSystemDetails.collectOsCommandOutputs(powershellOsSystemDetails); return nmapOsSystemDetails; } OperatingSystemDetectorService(SshOsDetectorService sshOsDetectorService, PowerShellOsDetectorService powershellOsDetectorService,
                                          NmapOsDetectorService nmapOsDetectorService, LocalOsDetectorService localOsDetectorService, OsDetectorHelperService osDetectorHelperService); }
OperatingSystemDetectorService implements OperatingSystemDetector { public OperatingSystemDetails detectOs(OsDetectorInputs osDetectorInputs) { OperatingSystemDetails localOsSystemDetails = localOsDetectorService.detectOs(osDetectorInputs); if (osDetectorHelperService.foundOperatingSystem(localOsSystemDetails)) { return localOsSystemDetails; } OperatingSystemDetails sshOsSystemDetails = sshOsDetectorService.detectOs(osDetectorInputs); sshOsSystemDetails.collectOsCommandOutputs(localOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(sshOsSystemDetails)) { return sshOsSystemDetails; } OperatingSystemDetails powershellOsSystemDetails = powershellOsDetectorService.detectOs(osDetectorInputs); powershellOsSystemDetails.collectOsCommandOutputs(sshOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(powershellOsSystemDetails)) { return powershellOsSystemDetails; } OperatingSystemDetails nmapOsSystemDetails = nmapOsDetectorService.detectOs(osDetectorInputs); nmapOsSystemDetails.collectOsCommandOutputs(powershellOsSystemDetails); return nmapOsSystemDetails; } OperatingSystemDetectorService(SshOsDetectorService sshOsDetectorService, PowerShellOsDetectorService powershellOsDetectorService,
                                          NmapOsDetectorService nmapOsDetectorService, LocalOsDetectorService localOsDetectorService, OsDetectorHelperService osDetectorHelperService); OperatingSystemDetails detectOs(OsDetectorInputs osDetectorInputs); }
OperatingSystemDetectorService implements OperatingSystemDetector { public OperatingSystemDetails detectOs(OsDetectorInputs osDetectorInputs) { OperatingSystemDetails localOsSystemDetails = localOsDetectorService.detectOs(osDetectorInputs); if (osDetectorHelperService.foundOperatingSystem(localOsSystemDetails)) { return localOsSystemDetails; } OperatingSystemDetails sshOsSystemDetails = sshOsDetectorService.detectOs(osDetectorInputs); sshOsSystemDetails.collectOsCommandOutputs(localOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(sshOsSystemDetails)) { return sshOsSystemDetails; } OperatingSystemDetails powershellOsSystemDetails = powershellOsDetectorService.detectOs(osDetectorInputs); powershellOsSystemDetails.collectOsCommandOutputs(sshOsSystemDetails); if (osDetectorHelperService.foundOperatingSystem(powershellOsSystemDetails)) { return powershellOsSystemDetails; } OperatingSystemDetails nmapOsSystemDetails = nmapOsDetectorService.detectOs(osDetectorInputs); nmapOsSystemDetails.collectOsCommandOutputs(powershellOsSystemDetails); return nmapOsSystemDetails; } OperatingSystemDetectorService(SshOsDetectorService sshOsDetectorService, PowerShellOsDetectorService powershellOsDetectorService,
                                          NmapOsDetectorService nmapOsDetectorService, LocalOsDetectorService localOsDetectorService, OsDetectorHelperService osDetectorHelperService); OperatingSystemDetails detectOs(OsDetectorInputs osDetectorInputs);  }