/** * Access a {@link ParseFile} value. This function will not perform a network request. Unless the * {@link ParseFile} has been downloaded (e.g. by calling {@link ParseFile#getData()}), * {@link ParseFile#isDataAvailable()} will return false. * * @param key The key to access the value for. * @return {@code null} if there is no such key or if it is not a {@link ParseFile}. */ public ParseFile getParseFile(String key) { return getParseFile(key, null); }
@Test public void testGetParseFileKeyExistValueNull() { ParseFile file = new ParseFile( new ParseFile.State.Builder().name("file.txt").url("http://yarr.com/file.txt").build()); final Map<String, Object> params = new HashMap<>(); params.put("key", JSONObject.NULL); params.put("keyAgain", JSONObject.NULL); ParseConfig config = new ParseConfig(params); assertNull(config.getParseFile("key")); assertNull(config.getParseFile("key", file)); assertNull(config.getParseFile("keyAgain")); assertNull(config.getParseFile("keyAgain", file)); }
@Test public void testGetParseFileKeyExistValueNotParseFile() { ParseFile file = new ParseFile( new ParseFile.State.Builder().name("file.txt").url("http://yarr.com/file.txt").build()); final Map<String, Object> params = new HashMap<>(); params.put("key", 1); ParseConfig config = new ParseConfig(params); assertNull(config.getParseFile("key")); assertSame(file, config.getParseFile("key", file)); }
@Test public void testGetParseFileKeyNotExist() { final ParseFile file = new ParseFile( new ParseFile.State.Builder().name("image.png").url("http://yarr.com/image.png").build()); ParseFile fileAgain = new ParseFile( new ParseFile.State.Builder().name("file.txt").url("http://yarr.com/file.txt").build()); final Map<String, Object> params = new HashMap<>(); params.put("key", file); ParseConfig config = new ParseConfig(params); assertNull(config.getParseFile("wrongKey")); assertSame(fileAgain, config.getParseFile("wrongKey", fileAgain)); }
@Test public void testGetParseFileKeyExist() { final ParseFile file = new ParseFile( new ParseFile.State.Builder().name("image.png").url("http://yarr.com/image.png").build()); ParseFile fileAgain = new ParseFile( new ParseFile.State.Builder().name("file.txt").url("http://yarr.com/file.txt").build()); final Map<String, Object> params = new HashMap<>(); params.put("key", file); ParseConfig config = new ParseConfig(params); ParseFile fileConfig = config.getParseFile("key"); assertEquals(file.getName(), fileConfig.getName()); assertEquals(file.getUrl(), fileConfig.getUrl()); assertSame(fileConfig, config.getParseFile("key", fileAgain)); }