@Test public void testSingleReference() throws DecisionTreeParserException { final ReferenceResolver resolver = mock(ReferenceResolver.class); when(resolver.resolveReference("b", "a")).thenReturn(true); final References references = new References(); references.addMapping("b", "a"); references.resolveAll(resolver); verify(resolver, atMost(1)).resolveReference("b", "a"); }
@Test public void refsInProject() throws Exception { final AndroidProject proj = (AndroidProject) ProjectManager.getDefault().findProject(projdir); AndroidGeneralData data = AndroidGeneralData.fromProject(proj); data.setPlatform(DalvikPlatformManager.getDefault().findPlatformForTarget("android-8")); proj.update(data); ReferenceResolver rr = new ProjectRefResolver(pp); List<ResourceRef> refs = rr.getReferences(); assertTrue(!refs.isEmpty()); assertTrue(refs.contains(new ResourceRef(true, "com.example.android.snake", "id", "snake"))); assertEquals(14, refs.size()); }
@Test public void testMissingReference() throws DecisionTreeParserException { final ReferenceResolver resolver = mock(ReferenceResolver.class); when(resolver.resolveReference("b", "a")).thenReturn(false); final References references = new References(); references.addMapping("b", "a"); try { references.resolveAll(resolver); fail("Should fail when the reference resolver cannot handle an input"); } catch (DecisionTreeParserException e) { verify(resolver, atMost(1)).resolveReference("b", "a"); } }
@Test public void testNestedReference_backwards() throws DecisionTreeParserException { // Same as the test above, but add the mappings backwards to verify the order doesn't matter final ReferenceResolver resolver = mock(ReferenceResolver.class); when(resolver.resolveReference("b", "c")).thenReturn(false).thenReturn(true); when(resolver.resolveReference("c", "a")).thenReturn(true); final References references = new References(); references.addMapping("c", "a"); references.addMapping("b", "c"); references.resolveAll(resolver); verify(resolver, atMost(1)).resolveReference("c", "a"); verify(resolver, atMost(2)).resolveReference("b", "c"); }