SpaceBackend { public static boolean isValid(String backendId) { if (!BACKEND_ID_PATTERN.matcher(backendId).matches()) return false; if (backendId.indexOf(SPACEDOG) > -1) return false; return true; } private  SpaceBackend(); String scheme(); String id(); String host(); int port(); boolean ssl(); boolean isMulti(); String name(); SpaceBackend name(String name); @Override String toString(); @Override boolean equals(Object object); StringBuilder urlBuilder(); String url(); String url(String path); static SpaceBackend fromUrl(String url); static SpaceBackend fromDefaults(String name); static SpaceBackend valueOf(String string); Optional<SpaceBackend> fromRequest(String requestHostAndPort); SpaceBackend fromBackendId(String backendId); static boolean isValid(String backendId); static void checkIsValid(String backendId); static final String API; static final String SPACEDOG; static SpaceBackend local; static SpaceBackend wwwLocal; static SpaceBackend staging; static SpaceBackend wwwStaging; static SpaceBackend production; static SpaceBackend wwwProduction; }
@Test public void testIsBackendIdValid() { assertTrue(SpaceBackend.isValid("a1234")); assertTrue(SpaceBackend.isValid("abcd")); assertTrue(SpaceBackend.isValid("1a2b34d")); assertFalse(SpaceBackend.isValid("a")); assertFalse(SpaceBackend.isValid("bb")); assertFalse(SpaceBackend.isValid("ccc")); assertFalse(SpaceBackend.isValid("dd-dd")); assertFalse(SpaceBackend.isValid("/eeee")); assertFalse(SpaceBackend.isValid("eeee:")); assertFalse(SpaceBackend.isValid("abcdE")); assertFalse(SpaceBackend.isValid("spacedog")); assertFalse(SpaceBackend.isValid("spacedog123")); assertFalse(SpaceBackend.isValid("123spacedog")); assertFalse(SpaceBackend.isValid("123spacedog123")); }