Skip to content

Commit

Permalink
Rename exception class to have Exception in the name
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-richardson committed May 31, 2016
1 parent 348d727 commit 3ef27ad
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public String toString() {
return String.format("%s;%s;%s;%s;%s;%s;%s", environmentId, latestDeployment, latestSuccessfulDeployment, releaseId, deploymentId, version, projectId);
}

public static Environment Parse(String toStringRepresentation) throws NeedToDeleteAndRecreateTrigger {
public static Environment Parse(String toStringRepresentation) throws NeedToDeleteAndRecreateTriggerException {
final Integer DONT_REMOVE_EMPTY_VALUES = -1;
final String[] split = toStringRepresentation.split(";", DONT_REMOVE_EMPTY_VALUES);

if (split.length < 4)
throw new NeedToDeleteAndRecreateTrigger();
throw new NeedToDeleteAndRecreateTriggerException();

final String environmentId = split[0];
final OctopusDate latestDeployment = OctopusDate.Parse(split[1]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.DeploymentComplete;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import com.mjrichardson.teamCity.buildTriggers.NullOctopusDate;
import com.mjrichardson.teamCity.buildTriggers.OctopusDate;
import jetbrains.buildServer.util.StringUtil;
Expand All @@ -26,7 +26,7 @@ public Environments(Environment environment) {
addOrUpdate(environment);
}

public static Environments Parse(String oldStoredData) throws ParseException, NeedToDeleteAndRecreateTrigger {
public static Environments Parse(String oldStoredData) throws ParseException, NeedToDeleteAndRecreateTriggerException {
Environments result = new Environments();

if (!StringUtil.isEmptyOrSpaces(oldStoredData)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.MachineAdded;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand Down Expand Up @@ -48,15 +48,15 @@ public static Machine Parse(Map item) {
return new Machine(id, name, environmentIds.toArray(new String[0]), roleIds.toArray(new String[0]));
}

public static Machine Parse(String pair) throws NeedToDeleteAndRecreateTrigger {
public static Machine Parse(String pair) throws NeedToDeleteAndRecreateTriggerException {
if (pair == null || pair.equals("")) {
return new NullMachine();
}
final Integer DONT_REMOVE_EMPTY_VALUES = -1;
final String[] split = pair.split(";", DONT_REMOVE_EMPTY_VALUES);

if (split.length < 4)
throw new NeedToDeleteAndRecreateTrigger();
throw new NeedToDeleteAndRecreateTriggerException();

final String id = split[0];
final String name = split[1];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.MachineAdded;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import jetbrains.buildServer.util.StringUtil;

import java.util.ArrayList;
Expand All @@ -13,7 +13,7 @@ public Machines() {
this.statusMap = new ArrayList<>();
}

public static Machines Parse(String oldStoredData) throws NeedToDeleteAndRecreateTrigger {
public static Machines Parse(String oldStoredData) throws NeedToDeleteAndRecreateTriggerException {
Machines result = new Machines();

if (!StringUtil.isEmptyOrSpaces(oldStoredData)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mjrichardson.teamCity.buildTriggers;

public class NeedToDeleteAndRecreateTrigger extends Exception {
public NeedToDeleteAndRecreateTrigger() {
public class NeedToDeleteAndRecreateTriggerException extends Exception {
public NeedToDeleteAndRecreateTriggerException() {
super("The way state is stored has been changed between your current version and the 2.x series.\n" +
"Please delete the trigger in TeamCity and re-add it.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.ReleaseCreated;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import com.mjrichardson.teamCity.buildTriggers.OctopusDate;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -37,7 +37,7 @@ public static Release Parse(Map item) {
return new Release(releaseId, assembledDate, version, projectId);
}

public static Release Parse(String pair) throws NeedToDeleteAndRecreateTrigger {
public static Release Parse(String pair) throws NeedToDeleteAndRecreateTriggerException {
if (pair == null || pair.equals("")) {
return new NullRelease();
}
Expand All @@ -48,7 +48,7 @@ public static Release Parse(String pair) throws NeedToDeleteAndRecreateTrigger {
final String version = split[2];

if (split.length < 4)
throw new NeedToDeleteAndRecreateTrigger();
throw new NeedToDeleteAndRecreateTriggerException();

final String projectId = split[3];

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.ReleaseCreated;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import jetbrains.buildServer.util.StringUtil;

import java.util.ArrayList;
Expand All @@ -13,7 +13,7 @@ public Releases() {
this.statusMap = new ArrayList<>();
}

public static Releases Parse(String data) throws NeedToDeleteAndRecreateTrigger {
public static Releases Parse(String data) throws NeedToDeleteAndRecreateTriggerException {
Releases releases = new Releases();

if (!StringUtil.isEmptyOrSpaces(data)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public void determine_outcome_of_fallback_handles_fewer_responses() {
Assert.assertEquals(result, AnalyticsTracker.EventAction.FallBackToDeploymentsApiProducedFewerEnvironments);
}

public void determine_outcome_of_fallback_handles_identical_responses() throws ParseException, NeedToDeleteAndRecreateTrigger {
public void determine_outcome_of_fallback_handles_identical_responses() throws ParseException, NeedToDeleteAndRecreateTriggerException {
HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey);
FakeAnalyticsTracker fakeAnalyticsTracker = new FakeAnalyticsTracker();
DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, fakeAnalyticsTracker);
Expand All @@ -330,7 +330,7 @@ public void determine_outcome_of_fallback_handles_identical_responses() throws P
Assert.assertEquals(result, AnalyticsTracker.EventAction.FallBackToDeploymentsApiProducedSameResults);
}

public void determine_outcome_of_fallback_handles_different_environments() throws ParseException, NeedToDeleteAndRecreateTrigger {
public void determine_outcome_of_fallback_handles_different_environments() throws ParseException, NeedToDeleteAndRecreateTriggerException {
HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey);
FakeAnalyticsTracker fakeAnalyticsTracker = new FakeAnalyticsTracker();
DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, fakeAnalyticsTracker);
Expand All @@ -345,7 +345,7 @@ public void determine_outcome_of_fallback_handles_different_environments() throw
Assert.assertEquals(result, AnalyticsTracker.EventAction.FallBackToDeploymentsApiProducedDifferentEnvironments);
}

public void determine_outcome_of_fallback_handles_response_with_newer_latest_deployment_date() throws ParseException, NeedToDeleteAndRecreateTrigger {
public void determine_outcome_of_fallback_handles_response_with_newer_latest_deployment_date() throws ParseException, NeedToDeleteAndRecreateTriggerException {
HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey);
FakeAnalyticsTracker fakeAnalyticsTracker = new FakeAnalyticsTracker();
DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, fakeAnalyticsTracker);
Expand All @@ -360,7 +360,7 @@ public void determine_outcome_of_fallback_handles_response_with_newer_latest_dep
Assert.assertEquals(result, AnalyticsTracker.EventAction.FallBackToDeploymentsApiProducedBetterInformation);
}

public void determine_outcome_of_fallback_handles_response_with_newer_successful_latest_deployment_date() throws ParseException, NeedToDeleteAndRecreateTrigger {
public void determine_outcome_of_fallback_handles_response_with_newer_successful_latest_deployment_date() throws ParseException, NeedToDeleteAndRecreateTriggerException {
HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey);
FakeAnalyticsTracker fakeAnalyticsTracker = new FakeAnalyticsTracker();
DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, fakeAnalyticsTracker);
Expand All @@ -375,7 +375,7 @@ public void determine_outcome_of_fallback_handles_response_with_newer_successful
Assert.assertEquals(result, AnalyticsTracker.EventAction.FallBackToDeploymentsApiProducedBetterInformation);
}

public void determine_outcome_of_fallback_handles_response_with_older_latest_deployment_date() throws ParseException, NeedToDeleteAndRecreateTrigger {
public void determine_outcome_of_fallback_handles_response_with_older_latest_deployment_date() throws ParseException, NeedToDeleteAndRecreateTriggerException {
HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey);
FakeAnalyticsTracker fakeAnalyticsTracker = new FakeAnalyticsTracker();
DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, fakeAnalyticsTracker);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.DeploymentComplete;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import com.mjrichardson.teamCity.buildTriggers.NullOctopusDate;
import com.mjrichardson.teamCity.buildTriggers.OctopusDate;
import org.testng.Assert;
Expand Down Expand Up @@ -115,13 +115,13 @@ public void parse_map_returns_deployment_with_null_latest_successful_deployment_
Assert.assertEquals(sut.projectId, "Project-8");
}

@Test(expectedExceptions = NeedToDeleteAndRecreateTrigger.class)
public void parse_string_throws_exception_if_format_is_different() throws NeedToDeleteAndRecreateTrigger {
@Test(expectedExceptions = NeedToDeleteAndRecreateTriggerException.class)
public void parse_string_throws_exception_if_format_is_different() throws NeedToDeleteAndRecreateTriggerException {
//the format changed (we added another 4 fields (releaseId, deploymentId, version, projectId)), so it needs to be deleted and recreated
Environment.Parse("env-id;2015-12-09T14:10:11.000+00:00;2015-12-12T09:04:03.000+00:00");
}

public void parse_string_populates_object_correctly() throws NeedToDeleteAndRecreateTrigger {
public void parse_string_populates_object_correctly() throws NeedToDeleteAndRecreateTriggerException {
Environment sut = Environment.Parse("Environment-1;2016-2-26T17:58:13.537+00:00;2016-2-26T17:58:13.537+00:00;Release-1;Deployment-1;1.0.1;Project-8");
Assert.assertEquals(sut.environmentId, "Environment-1");
Assert.assertEquals(sut.latestDeployment, new OctopusDate(2016, 2, 26, 17, 58, 13, 537));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void get_changed_deployment_throws_exception_when_none_changed() throws E
newEnvironments.getChangedDeployment(oldEnvironments);
}

public void to_array_converts_deployments_to_array_successfully() throws ParseException, NeedToDeleteAndRecreateTrigger {
public void to_array_converts_deployments_to_array_successfully() throws ParseException, NeedToDeleteAndRecreateTriggerException {
final String data = "Environments-1;2016-01-19T14:00:00.000+00:00;2016-01-19T00:00:00.000+00:00;the-release-id;the-deployment-id;the-version;the-project-id|Environments-21;2016-01-20T14:00:00.000+00:00;2016-01-20T14:00:00.000+00:00;the-release-id;the-deployment-id;the-version;the-project-id";
Environments environments = Environments.Parse(data);
Environment[] array = environments.toArray();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.MachineAdded;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -10,40 +10,40 @@

@Test
public class MachineTest {
public void can_parse_empty_string_to_null_machine() throws NeedToDeleteAndRecreateTrigger {
public void can_parse_empty_string_to_null_machine() throws NeedToDeleteAndRecreateTriggerException {
Machine sut = Machine.Parse("");
Assert.assertEquals(sut.getClass(), NullMachine.class);
}

public void can_parse_null_string_to_null_machine() throws NeedToDeleteAndRecreateTrigger {
public void can_parse_null_string_to_null_machine() throws NeedToDeleteAndRecreateTriggerException {
Machine sut = Machine.Parse((String)null);
Assert.assertEquals(sut.getClass(), NullMachine.class);
}

public void can_parse_valid_string_to_machine() throws NeedToDeleteAndRecreateTrigger {
public void can_parse_valid_string_to_machine() throws NeedToDeleteAndRecreateTriggerException {
Machine sut = Machine.Parse("Machines-91;MachineNinetyOne;env-1,env-2;role-one,role-two");
Assert.assertEquals(sut.id, "Machines-91");
Assert.assertEquals(sut.name, "MachineNinetyOne");
}

public void to_string_formats_correctly() throws NeedToDeleteAndRecreateTrigger {
public void to_string_formats_correctly() throws NeedToDeleteAndRecreateTriggerException {
Machine sut = Machine.Parse("Machines-91;MachineNinetyOne;env-1,env-2;role-one,role-two");
Assert.assertEquals(sut.toString(), "Machines-91;MachineNinetyOne;env-1,env-2;role-one,role-two");
}

public void compare_returns_1_when_passed_machine_has_lower_id() throws NeedToDeleteAndRecreateTrigger {
public void compare_returns_1_when_passed_machine_has_lower_id() throws NeedToDeleteAndRecreateTriggerException {
Machine machine1 = Machine.Parse("Machines-1;MachineOne;env-1,env-2;role-one,role-two");
Machine machine2 = Machine.Parse("Machines-2;MachineTwo;env-1,env-2;role-one,role-two");
Assert.assertEquals(machine2.compareTo(machine1), 1);
}

public void compare_returns_0_when_passed_machine_has_same_id() throws NeedToDeleteAndRecreateTrigger {
public void compare_returns_0_when_passed_machine_has_same_id() throws NeedToDeleteAndRecreateTriggerException {
Machine machine1 = Machine.Parse("Machines-1;MachineOne;env-1,env-2;role-one,role-two");
Machine machine2 = Machine.Parse("Machines-1;MachineOneAgain;env-1,env-2;role-one,role-two");
Assert.assertEquals(machine1.compareTo(machine2), 0);
}

public void compare_returns_minus_1_when_passed_machine_has_higher_id() throws NeedToDeleteAndRecreateTrigger {
public void compare_returns_minus_1_when_passed_machine_has_higher_id() throws NeedToDeleteAndRecreateTriggerException {
Machine machine1 = Machine.Parse("Machines-3;MachineOne;env-1,env-2;role-one,role-two");
Machine machine2 = Machine.Parse("Machines-21;MachineTwo;env-1,env-2;role-one,role-two");
Assert.assertEquals(machine1.compareTo(machine2), -1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.MachineAdded;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -78,7 +78,7 @@ public void get_next_machine_returns_next_machine() throws Exception {
Assert.assertEquals(machine, firstNewMachine);
}

public void to_array_converts_machines_to_array_successfully() throws NeedToDeleteAndRecreateTrigger {
public void to_array_converts_machines_to_array_successfully() throws NeedToDeleteAndRecreateTriggerException {
final Machine oldMachine = new Machine("machine-2", "MachineTwo", new String[] { "env-id" }, new String[]{ "role-name" });
final Machine newMachine = new Machine("machine-3", "MachineThree", new String[] { "env-id" }, new String[]{ "role-name" });
Machines machines = Machines.Parse(String.format("%s|%s", oldMachine.toString(), newMachine.toString()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.MachineAdded;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand All @@ -12,7 +12,7 @@ public void null_machine_sets_fields_to_empty() {
Assert.assertEquals(sut.name, "");
}

public void can_parse_to_null_machine() throws NeedToDeleteAndRecreateTrigger {
public void can_parse_to_null_machine() throws NeedToDeleteAndRecreateTriggerException {
Machine sut = Machine.Parse(new NullMachine().toString());
Assert.assertEquals(sut.getClass(), NullMachine.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mjrichardson.teamCity.buildTriggers.ReleaseCreated;

import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTrigger;
import com.mjrichardson.teamCity.buildTriggers.NeedToDeleteAndRecreateTriggerException;
import com.mjrichardson.teamCity.buildTriggers.NullOctopusDate;
import org.testng.Assert;
import org.testng.annotations.Test;
Expand All @@ -14,7 +14,7 @@ public void null_release_sets_fields_to_empty() {
Assert.assertEquals(sut.version, "");
}

public void can_parse_to_null_release() throws NeedToDeleteAndRecreateTrigger {
public void can_parse_to_null_release() throws NeedToDeleteAndRecreateTriggerException {
Release sut = Release.Parse(new NullRelease().toString());
Assert.assertEquals(sut.getClass(), NullRelease.class);
}
Expand Down
Loading

0 comments on commit 3ef27ad

Please sign in to comment.