Skip to content

Commit

Permalink
Use consistent naming scheme for test classes and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nmiyake committed Jun 4, 2016
1 parent 216ed63 commit c333782
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class DockerComposeRuleTest {
public class DockerComposeRuleShould {

private static final String IP = "127.0.0.1";

Expand All @@ -85,21 +85,21 @@ public class DockerComposeRuleTest {
}

@Test
public void docker_compose_build_and_up_is_called_before_tests_are_run() throws IOException, InterruptedException {
public void call_build_and_up_before_tests_are_run() throws IOException, InterruptedException {
rule.before();
verify(dockerCompose).build();
verify(dockerCompose).up();
}

@Test
public void docker_compose_kill_and_rm_are_called_after_tests_are_run() throws IOException, InterruptedException {
public void call_kill_and_rm_after_tests_are_run() throws IOException, InterruptedException {
rule.after();
verify(dockerCompose).kill();
verify(dockerCompose).rm();
}

@Test
public void docker_compose_wait_for_service_passes_when_check_is_true() throws IOException, InterruptedException {
public void pass_wait_for_service_when_check_is_true() throws IOException, InterruptedException {
AtomicInteger timesCheckCalled = new AtomicInteger(0);
withComposeExecutableReturningContainerFor("db");
HealthCheck<Container> checkCalledOnce = (container) -> SuccessOrFailure.fromBoolean(timesCheckCalled.incrementAndGet() == 1, "not called once yet");
Expand All @@ -108,7 +108,7 @@ public void docker_compose_wait_for_service_passes_when_check_is_true() throws I
}

@Test
public void docker_compose_wait_for_service_waits_multiple_services() throws IOException, InterruptedException {
public void wait_for_multiple_services_on_wait() throws IOException, InterruptedException {
Container db1 = withComposeExecutableReturningContainerFor("db1");
Container db2 = withComposeExecutableReturningContainerFor("db2");
List<Container> containers = ImmutableList.of(db1, db2);
Expand All @@ -122,7 +122,7 @@ public void docker_compose_wait_for_service_waits_multiple_services() throws IOE
}

@Test
public void docker_compose_wait_for_service_passes_when_check_is_true_after_being_false() throws IOException, InterruptedException {
public void pass_wait_for_service_when_check_is_true_after_being_false() throws IOException, InterruptedException {
AtomicInteger timesCheckCalled = new AtomicInteger(0);
withComposeExecutableReturningContainerFor("db");
HealthCheck<Container> checkCalledTwice = (container) -> SuccessOrFailure.fromBoolean(timesCheckCalled.incrementAndGet() == 2, "not called twice yet");
Expand All @@ -131,7 +131,8 @@ public void docker_compose_wait_for_service_passes_when_check_is_true_after_bein
}

@Test
public void throws_if_a_wait_for_service_check_remains_false_till_the_timeout() throws IOException, InterruptedException {
public void throw_exception_if_a_wait_for_service_check_remains_false_until_the_timeout()
throws IOException, InterruptedException {
withComposeExecutableReturningContainerFor("db");

exception.expect(IllegalStateException.class);
Expand All @@ -142,7 +143,7 @@ public void throws_if_a_wait_for_service_check_remains_false_till_the_timeout()
}

@Test
public void port_for_container_can_be_retrieved_by_external_mapping() throws IOException, InterruptedException {
public void retrieve_port_for_container_by_external_mapping() throws IOException, InterruptedException {
DockerPort expectedPort = env.port("db", IP, 5433, 5432);
withComposeExecutableReturningContainerFor("db");

Expand All @@ -152,7 +153,7 @@ public void port_for_container_can_be_retrieved_by_external_mapping() throws IOE
}

@Test
public void port_for_container_can_be_retrieved_by_internal_mapping() throws IOException, InterruptedException {
public void retrieve_port_for_container_by_internal_mapping() throws IOException, InterruptedException {
DockerPort expectedPort = env.port("db", IP, 5433, 5432);
withComposeExecutableReturningContainerFor("db");

Expand All @@ -162,7 +163,7 @@ public void port_for_container_can_be_retrieved_by_internal_mapping() throws IOE
}

@Test
public void when_two_external_ports_on_a_container_are_requested_docker_compose_ps_is_only_executed_once() throws Exception {
public void execute_ps_once_when_two_external_ports_on_a_container_are_requested() throws Exception {
env.ports("db", IP, 5432, 8080);
withComposeExecutableReturningContainerFor("db");

Expand All @@ -173,7 +174,8 @@ public void when_two_external_ports_on_a_container_are_requested_docker_compose_
}

@Test
public void waiting_for_service_that_does_not_exist_results_in_an_illegal_state_exception() throws IOException, InterruptedException {
public void throw_illegal_state_exception_when_waiting_for_service_that_does_not_exist()
throws IOException, InterruptedException {
String nonExistentContainer = "nonExistent";
when(dockerCompose.ports(nonExistentContainer))
.thenThrow(new IllegalStateException("No container with name 'nonExistent' found"));
Expand All @@ -187,7 +189,8 @@ public void waiting_for_service_that_does_not_exist_results_in_an_illegal_state_

@SuppressWarnings("unchecked")
@Test
public void logs_can_be_saved_to_a_directory_while_containers_are_running() throws IOException, InterruptedException {
public void be_able_to_save_logs_to_a_directory_while_containers_are_running()
throws IOException, InterruptedException {
File logLocation = logFolder.newFolder();
DockerComposeRule loggingComposition = DockerComposeRule.builder().from(rule).saveLogsTo(logLocation.getAbsolutePath()).build();
when(dockerCompose.ps()).thenReturn(new ContainerNames("db"));
Expand All @@ -206,7 +209,7 @@ public void logs_can_be_saved_to_a_directory_while_containers_are_running() thro
}

@Test
public void when_skipShutdown_is_true_shutdown_does_not_happen() throws InterruptedException {
public void not_shut_down_when_skipShutdown_is_true() throws InterruptedException {
defaultBuilder().skipShutdown(true)
.build()
.after();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class AdditionalEnvironmentValidatorTest {
public class AdditionalEnvironmentValidatorShould {

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void additional_environment_variables_with_docker_variables() throws Exception {
public void throw_exception_when_additional_environment_variables_contain_docker_variables() throws Exception {
Map<String, String> variables = ImmutableMap.<String, String>builder().put("DOCKER_HOST", "tcp://some-host:2376")
.put("SOME_VARIABLE", "Some Value")
.build();
Expand All @@ -42,7 +42,7 @@ public void additional_environment_variables_with_docker_variables() throws Exce
}

@Test
public void valid_arbitrary_environment_variables() throws Exception {
public void validate_arbitrary_environment_variables() throws Exception {
Map<String, String> variables = ImmutableMap.<String, String>builder().put("SOME_VARIABLE", "Some Value")
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class DaemonEnvironmentValidatorTest {
public class DaemonEnvironmentValidatorShould {

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void docker_environment_does_not_contain_docker_variables() throws Exception {
public void validate_successfully_when_docker_environment_does_not_contain_docker_variables() throws Exception {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put("SOME_VARIABLE", "SOME_VALUE")
.put("ANOTHER_VARIABLE", "ANOTHER_VALUE")
Expand All @@ -43,7 +43,7 @@ public void docker_environment_does_not_contain_docker_variables() throws Except
}

@Test
public void docker_environment_contains_illegal_docker_variables() throws Exception {
public void throw_exception_when_docker_environment_contains_illegal_docker_variables() throws Exception {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put(DOCKER_HOST, "tcp://192.168.99.100:2376")
.put(DOCKER_TLS_VERIFY, "1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@

import org.junit.Test;

public class DaemonHostIpResolverTest {
public class DaemonHostIpResolverShould {

@Test
public void daemon_returns_local_host_with_null() throws Exception {
public void return_local_host_with_null() throws Exception {
assertThat(new DaemonHostIpResolver().resolveIp(null), is(LOCALHOST));
}

@Test
public void daemon_returns_local_host_with_blank() throws Exception {
public void return_local_host_with_blank() throws Exception {
assertThat(new DaemonHostIpResolver().resolveIp(""), is(LOCALHOST));
}

@Test
public void daemon_returns_local_host_with_arbitrary() throws Exception {
public void return_local_host_with_arbitrary() throws Exception {
assertThat(new DaemonHostIpResolver().resolveIp("arbitrary"), is(LOCALHOST));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;

public class DockerComposeFilesTest {
public class DockerComposeFilesShould {

@Rule
public final TemporaryFolder tempFolder = new TemporaryFolder();
Expand All @@ -35,14 +35,14 @@ public class DockerComposeFilesTest {
public final ExpectedException exception = ExpectedException.none();

@Test
public void notSpecifyingAComposeFileResultsInError() throws Exception {
public void throw_exception_when_compose_file_is_not_specified() throws Exception {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("A docker compose file must be specified.");
DockerComposeFiles.from();
}

@Test
public void missingDockerComposeFileThrowsAnException() throws Exception {
public void throw_exception_when_compose_file_does_not_exist() throws Exception {
exception.expect(IllegalStateException.class);
exception.expectMessage("The following docker-compose files:");
exception.expectMessage("does-not-exist.yaml");
Expand All @@ -51,7 +51,9 @@ public void missingDockerComposeFileThrowsAnException() throws Exception {
}

@Test
public void aSingleMissingComposeFileWithAnExistingComposeFileThrowsCorrectException() throws Exception {
public void
throw_correct_exception_when_there_is_a_single_missing_compose_file_with_an_existing_compose_file()
throws Exception {
exception.expect(IllegalStateException.class);
exception.expectMessage("The following docker-compose files:");
exception.expectMessage("does-not-exist.yaml");
Expand All @@ -63,14 +65,14 @@ public void aSingleMissingComposeFileWithAnExistingComposeFileThrowsCorrectExcep
}

@Test
public void dockerComposeFileCommandGetsGeneratedCorrectly_singleComposeFile() throws Exception {
public void generate_docker_compose_file_command_correctly_for_single_compose_file() throws Exception {
File composeFile = tempFolder.newFile("docker-compose.yaml");
DockerComposeFiles dockerComposeFiles = DockerComposeFiles.from(composeFile.getAbsolutePath());
assertThat(dockerComposeFiles.constructComposeFileCommand(), contains("--file", composeFile.getAbsolutePath()));
}

@Test
public void dockerComposeFileCommandGetsGeneratedCorrectly_multipleComposeFile() throws Exception {
public void generate_docker_compose_file_command_correctly_for_multiple_compose_files() throws Exception {
File composeFile1 = tempFolder.newFile("docker-compose1.yaml");
File composeFile2 = tempFolder.newFile("docker-compose2.yaml");
DockerComposeFiles dockerComposeFiles = DockerComposeFiles.from(composeFile1.getAbsolutePath(), composeFile2.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,54 +27,54 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class ProjectNameTest {
public class ProjectNameShould {

@Rule
public final ExpectedException exception = ExpectedException.none();

@Test
public void construct_compose_command_should_use_project_name_prefix() {
public void use_project_name_prefix_in_construct_compose_command() {
List<String> command = ProjectName.random().constructComposeFileCommand();

assertThat(command, hasSize(2));
assertThat(command.get(0), is("--project-name"));
}

@Test
public void successive_calls_to_random_should_produce_different_names() {
public void produce_different_names_on_successive_calls_to_random() {
List<String> firstCommand = ProjectName.random().constructComposeFileCommand();
List<String> secondCommand = ProjectName.random().constructComposeFileCommand();

assertThat(firstCommand, is(not(equalTo(secondCommand))));
}

@Test
public void random_should_be_eight_characters_long() {
public void have_eight_characters_long_random() {
String randomName = ProjectName.random().constructComposeFileCommand().get(1);
assertThat(randomName.length(), is(8));
}

@Test
public void from_string_factory_should_pass_name_to_command() {
public void should_pass_name_to_command_in_from_string_factory() {
List<String> command = ProjectName.fromString("projectname").constructComposeFileCommand();
assertThat(command, contains("--project-name", "projectname"));
}

@Test
public void from_string_factory_should_disallow_names() {
public void should_disallow_names_in_from_string_factory() {
List<String> command = ProjectName.fromString("projectname").constructComposeFileCommand();
assertThat(command, contains("--project-name", "projectname"));
}

@Test
public void from_string_should_reject_blanks() {
public void reject_blanks_in_from_string() {
exception.expect(IllegalStateException.class);
exception.expectMessage("ProjectName must not be blank.");
ProjectName.fromString(" ");
}

@Test
public void validation_should_match_docker_compose_cli() {
public void match_validation_behavior_of_docker_compose_cli() {
exception.expect(IllegalStateException.class);
exception.expectMessage("ProjectName 'Crazy#Proj ect!Name' not allowed, please use lowercase letters and numbers only.");
ProjectName.fromString("Crazy#Proj ect!Name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class RemoteEnvironmentValidatorTest {
public class RemoteEnvironmentValidatorShould {

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void docker_host_is_required_to_be_set() throws Exception {
public void throw_exception_if_docker_host_is_not_set() throws Exception {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put("SOME_VARIABLE", "SOME_VALUE")
.build();
Expand All @@ -45,7 +45,7 @@ public void docker_host_is_required_to_be_set() throws Exception {
}

@Test
public void docker_cert_path_is_required_if_tls_is_on() throws Exception {
public void throw_exception_if_docker_cert_path_is_missing_and_tls_is_on() throws Exception {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put(DOCKER_HOST, "tcp://192.168.99.100:2376")
.put(DOCKER_TLS_VERIFY, "1")
Expand All @@ -59,7 +59,7 @@ public void docker_cert_path_is_required_if_tls_is_on() throws Exception {
}

@Test
public void environment_with_all_valid_variables_set_without_t_l_s() throws Exception {
public void validate_environment_with_all_valid_variables_set_without_tls() throws Exception {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put(DOCKER_HOST, "tcp://192.168.99.100:2376")
.put("SOME_VARIABLE", "SOME_VALUE")
Expand All @@ -69,7 +69,7 @@ public void environment_with_all_valid_variables_set_without_t_l_s() throws Exce
}

@Test
public void environment_with_all_valid_variables_set_with_t_l_s() throws Exception {
public void validate_environment_with_all_valid_variables_set_with_tls() throws Exception {
Map<String, String> variables = ImmutableMap.<String, String>builder()
.put(DOCKER_HOST, "tcp://192.168.99.100:2376")
.put(DOCKER_TLS_VERIFY, "1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class RemoteHostIpResolverTest {
public class RemoteHostIpResolverShould {

private static final String IP = "192.168.99.100";
private static final int PORT = 2376;
Expand All @@ -32,14 +32,14 @@ public class RemoteHostIpResolverTest {
public ExpectedException exception = ExpectedException.none();

@Test
public void resolving_invalid_docker_host_results_in_error_blank() throws Exception {
public void result_in_error_blank_when_resolving_invalid_docker_host() throws Exception {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("DOCKER_HOST cannot be blank/null");
new RemoteHostIpResolver().resolveIp("");
}

@Test
public void resolving_invalid_docker_host_results_in_error_null() throws Exception {
public void result_in_error_null_when_resolving_invalid_docker_host() throws Exception {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("DOCKER_HOST cannot be blank/null");
new RemoteHostIpResolver().resolveIp(null);
Expand Down
Loading

0 comments on commit c333782

Please sign in to comment.