DockerVersionVerifier { @PostConstruct void checkCompatibility() throws ServerException { try { Version versionInfo = dockerConnector.getVersion(); if (!supportedVersions.contains(versionInfo.getVersion())) { throw new ServerException("Unsupported docker version " + versionInfo.getVersion()); } } catch (IOException e) { LOG.info(e.getMessage()); throw new ServerException("Impossible to get docker version", e); } } @Inject  DockerVersionVerifier(DockerConnector dockerConnector, @Named("machine.supported_docker_version") String[] supportedVersions);   }
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Unsupported docker version x.x.x") public void shouldThrowServerExceptionWhenDockerVersionIsIncompatible() throws Exception { Version version = new Version(); version.setVersion("x.x.x"); when(dockerConnector.getVersion()).thenReturn(version); DockerVersionVerifier verifier = new DockerVersionVerifier(dockerConnector, new String[]{"1.6.0"}); verifier.checkCompatibility(); }
@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Impossible to get docker version") public void shouldThrowIOExceptionWhenVersionJsonParsing() throws Exception { when(dockerConnector.getVersion()).thenThrow(new IOException()); DockerVersionVerifier verifier = new DockerVersionVerifier(dockerConnector, new String[]{"1.6.0"}); verifier.checkCompatibility(); }
@Test public void supportedVersionTest() throws Exception { Version version = new Version(); version.setVersion("1.6.0"); when(dockerConnector.getVersion()).thenReturn(version); DockerVersionVerifier verifier = new DockerVersionVerifier(dockerConnector, new String[]{"1.6.0"}); verifier.checkCompatibility(); }