SourceOrigins { public ApiLevel getApiLevelByVersion(Version version) { ApiLevel last = null; Iterator<ApiLevel> reviter = apilevels.descendingIterator(); int diff; while (reviter.hasNext()) { ApiLevel api = reviter.next(); diff = api.getVersion().compareTo(version); if (diff > 0) { last = api; continue; } else if (diff == 0) { return api; } else { return last; } } return last; }  Map<Version, VersionTree> getVersions(); void setVersions(Map<Version, VersionTree> versions); int getSpecVersion(); void setSpecVersion(int specVersion); Set<ApiLevel> getApilevels(); Collection<ProjectTemplate> getProjects(); void setApilevels(Set<ApiLevel> apis); @SetNext void addProject(ProjectTemplate project); @SetNext void addApiLevel(ApiLevel apilevel); Set<Tag> getTags(); void setTags(Set<Tag> tags); @SetNext void addTag(Tag tag); Set<Branch> getBranches(); void setBranches(Set<Branch> branches); @SetNext void addBranch(Branch branch); Set<Repo> getRepos(); void setRepos(Set<Repo> repos); @SetNext void addRepo(Repo repo); ApiLevel getApiLevel(String level); Tag getTag(String name); Branch getBranch(String name); Repo getRepo(String url); void normalize(); ApiLevel getApiLevelByVersion(Version version); VersionTree getVersion(String version); List<FetchTarget> getFetchTargets(); FetchTarget getFetchTarget(String id); ProjectTemplate getProjectTemplate(String id);  }
@Test public void testGetApiLevelByVersion() throws IOException { SourceOrigins origins = SourceOriginsLoader.load(); ApiLevel api = origins.getApiLevelByVersion(new Version("2.3.1")); Assert.assertThat("version 2.3.1 -> ApiLevel", api, notNullValue()); Assert.assertThat("version 2.3.1 -> ApiLevel.version", api.getVersion(), is(new Version("2.3"))); Assert.assertThat("version 2.3.1 -> ApiLevel.level", api.getLevel(), is("9")); Assert.assertThat("version 2.3.1 -> ApiLevel.codename", api.getCodename(), is("gingerbread")); }