Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Parsing invalid serialized Bind throws IllegalArgumentException
  • Loading branch information
albers committed Sep 28, 2014
commit ed92136784dfa31477392e4f4f61d63d072e4b23
9 changes: 4 additions & 5 deletions src/main/java/com/github/dockerjava/api/model/Bind.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public boolean isReadOnly() {
*
* @param serialized the specification, e.g. <code>/host:/container:ro</code>
* @return a {@link Bind} matching the specification
* @throws IllegalArgumentException if the specification cannot be parsed
*/
public static Bind parse(String serialized) {
try {
Expand All @@ -52,16 +53,14 @@ public static Bind parse(String serialized) {
else if ("ro".equals(parts[2].toLowerCase()))
return new Bind(parts[0], Volume.parse(parts[1]), true);
else
throw new RuntimeException("Error parsing Bind '"
+ serialized + "'");
throw new IllegalArgumentException();
}
default: {
throw new RuntimeException("Error parsing Bind '" + serialized
+ "'");
throw new IllegalArgumentException();
}
}
} catch (Exception e) {
throw new RuntimeException("Error parsing Bind '" + serialized
throw new IllegalArgumentException("Error parsing Bind '" + serialized
+ "'");
}
}
Expand Down
17 changes: 15 additions & 2 deletions src/test/java/com/github/dockerjava/api/model/BindTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,22 @@ public void parseReadOnly() {
assertEquals(bind.isReadOnly(), true);
}

@Test(expectedExceptions = RuntimeException.class)
@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = "Error parsing Bind.*")
public void parseInvalidAccessMode() {
Bind.parse("/host:/container:xx");
}


@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = "Error parsing Bind 'nonsense'")
public void parseInvalidInput() {
Bind.parse("nonsense");
}

@Test(expectedExceptions = IllegalArgumentException.class,
expectedExceptionsMessageRegExp = "Error parsing Bind 'null'")
public void parseNull() {
Bind.parse(null);
}

}