VolumeParser extends NonParameterizedTypeParser<Volume> { @Override public Volume doParse(String raw) throws IllegalArgumentException { String[] split = raw.split(":"); if (split.length != 3) { throw new IllegalArgumentException("Illegal mount string " + raw + ". " + "Mounts must be in the format of 'host:container:mode'"); } Mode mode; try { mode = Mode.valueOf(split[2].toUpperCase()); } catch (IllegalArgumentException e) { throw new IllegalArgumentException("Illegal mount string " + raw + ". " + "Read/Write spec must be in " + Joiner.on(", ").join(Mode.values()), e); } return new Volume(split[1], split[0], mode); }  @Override Volume doParse(String raw);  }
@Test public void testValidConfig() { assertEquals( new Volume("/container", "/host", Mode.RO), volumeParser.doParse("/host:/container:ro")); }
@Test(expected = IllegalArgumentException.class) public void testInvalidConfig() { volumeParser.doParse("/host,nope"); }
@Test(expected = IllegalArgumentException.class) public void testInvalidMode() { volumeParser.doParse("/host:/container:RE"); }
@Test(expected = IllegalArgumentException.class) public void testTooManySegments() { volumeParser.doParse("/host:/container:RO:bonusdata"); }