ItEr24S08CUAsignacionGrupoRecursosAPlanificacionItEr23S10: Creating ScriptDependency class representing a dependency.
This commit is contained in:
parent
f3c665aa8d
commit
49d7989fdb
2 changed files with 125 additions and 0 deletions
|
|
@ -0,0 +1,55 @@
|
|||
package org.zkoss.ganttz.util.script;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
/**
|
||||
* Represents a dependency to a script
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public class ScriptDependency {
|
||||
|
||||
private final String url;
|
||||
private final List<ScriptDependency> dependsOn;
|
||||
|
||||
public ScriptDependency(String url) {
|
||||
this(url, Collections.<ScriptDependency> emptyList());
|
||||
}
|
||||
|
||||
public ScriptDependency(String url, Collection<? extends ScriptDependency> dependencies) {
|
||||
Validate.notEmpty(url);
|
||||
Validate.noNullElements(dependencies);
|
||||
this.url = url;
|
||||
this.dependsOn = Collections.unmodifiableList(new ArrayList<ScriptDependency>(
|
||||
dependencies));
|
||||
}
|
||||
|
||||
public String getURL() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public List<ScriptDependency> getDependsOn() {
|
||||
return dependsOn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (this == other)
|
||||
return true;
|
||||
if (other instanceof ScriptDependency) {
|
||||
return url.equals(((ScriptDependency) other).url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder().append(url).toHashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package org.zkoss.ganttz.util.script;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ScriptDependencyTest {
|
||||
|
||||
private ScriptDependency script;
|
||||
private String url;
|
||||
private List<ScriptDependency> dependencies;
|
||||
|
||||
private void givenScript() {
|
||||
url = "blabla/zkau/web/js/yui/2.7.0/selector/selector-min.js";
|
||||
dependencies = new ArrayList<ScriptDependency>();
|
||||
dependencies.add(new ScriptDependency("blabla/blabla/bla.js"));
|
||||
script = new ScriptDependency(url, dependencies);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aScriptHasAURL() {
|
||||
givenScript();
|
||||
assertThat(script.getURL(), equalTo(url));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void theURLMustBeNotNull() {
|
||||
new ScriptDependency(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void theURLMustBeNotEmpty() {
|
||||
new ScriptDependency("");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void noDependenciesCanBeNull() {
|
||||
List<ScriptDependency> list = new ArrayList<ScriptDependency>();
|
||||
list.add(null);
|
||||
new ScriptDependency("bla", list);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aScriptCanHaveDependencies() {
|
||||
givenScript();
|
||||
assertThat(script.getDependsOn(), equalTo(dependencies));
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void theDependenciesCannotBeModified() {
|
||||
givenScript();
|
||||
script.getDependsOn().clear();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void twoScriptsAreEqualsIfHaveTheSameURL() {
|
||||
givenScript();
|
||||
ScriptDependency scriptDependencyWithSameURL = new ScriptDependency(url);
|
||||
assertThat(scriptDependencyWithSameURL, equalTo(script));
|
||||
assertThat(scriptDependencyWithSameURL.hashCode(), equalTo(script
|
||||
.hashCode()));
|
||||
assertThat(new ScriptDependency(url + "b"), not(equalTo(script)));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue