X Tutup
Skip to content

Commit ed92136

Browse files
committed
Parsing invalid serialized Bind throws IllegalArgumentException
1 parent 1b74f6c commit ed92136

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/main/java/com/github/dockerjava/api/model/Bind.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public boolean isReadOnly() {
3838
*
3939
* @param serialized the specification, e.g. <code>/host:/container:ro</code>
4040
* @return a {@link Bind} matching the specification
41+
* @throws IllegalArgumentException if the specification cannot be parsed
4142
*/
4243
public static Bind parse(String serialized) {
4344
try {
@@ -52,16 +53,14 @@ public static Bind parse(String serialized) {
5253
else if ("ro".equals(parts[2].toLowerCase()))
5354
return new Bind(parts[0], Volume.parse(parts[1]), true);
5455
else
55-
throw new RuntimeException("Error parsing Bind '"
56-
+ serialized + "'");
56+
throw new IllegalArgumentException();
5757
}
5858
default: {
59-
throw new RuntimeException("Error parsing Bind '" + serialized
60-
+ "'");
59+
throw new IllegalArgumentException();
6160
}
6261
}
6362
} catch (Exception e) {
64-
throw new RuntimeException("Error parsing Bind '" + serialized
63+
throw new IllegalArgumentException("Error parsing Bind '" + serialized
6564
+ "'");
6665
}
6766
}

src/test/java/com/github/dockerjava/api/model/BindTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,22 @@ public void parseReadOnly() {
3030
assertEquals(bind.isReadOnly(), true);
3131
}
3232

33-
@Test(expectedExceptions = RuntimeException.class)
33+
@Test(expectedExceptions = IllegalArgumentException.class,
34+
expectedExceptionsMessageRegExp = "Error parsing Bind.*")
3435
public void parseInvalidAccessMode() {
3536
Bind.parse("/host:/container:xx");
3637
}
37-
38+
39+
@Test(expectedExceptions = IllegalArgumentException.class,
40+
expectedExceptionsMessageRegExp = "Error parsing Bind 'nonsense'")
41+
public void parseInvalidInput() {
42+
Bind.parse("nonsense");
43+
}
44+
45+
@Test(expectedExceptions = IllegalArgumentException.class,
46+
expectedExceptionsMessageRegExp = "Error parsing Bind 'null'")
47+
public void parseNull() {
48+
Bind.parse(null);
49+
}
50+
3851
}

0 commit comments

Comments
 (0)
X Tutup