MCPcopy
hub / github.com/Col-E/Recaf / testClassReference

Method testClassReference

src/test/java/me/coley/recaf/SearchTest.java:162–194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

160 }
161
162 @Test
163 public void testClassReference() {
164 // Setup search - References to the "Exponent" class
165 // - Should be 3 references in "Exponent"
166 // - 2 "this" variables in "calc/Exponent"
167 // - 1 type reference in "calc/Calculator"
168 SearchCollector collector = SearchBuilder.in(workspace)
169 .query(new ClassReferenceQuery("calc/Exponent")).build();
170 // Show results
171 List<SearchResult> results = collector.getAllResults();
172 assertEquals(3, results.size());
173 int calc = 0, exp = 0;
174 for (SearchResult res : results) {
175 if (res.getContext() instanceof Context.InsnContext) {
176 Context.InsnContext insnContext = (Context.InsnContext) res.getContext();
177 String owner = insnContext.getParent().getParent().getName();
178 if (!owner.equals("calc/Calculator"))
179 fail("Unexpected result in: " + owner);
180 calc++;
181 } else if(res.getContext() instanceof Context.LocalContext) {
182 Context.LocalContext localContext = (Context.LocalContext) res.getContext();
183 String owner = localContext.getParent().getParent().getName();
184 if (!owner.equals("calc/Exponent"))
185 fail("Unexpected result in: " + owner);
186 exp++;
187 }
188 }
189 // - LOCAL this
190 // - LOCAL this
191 assertEquals(2, exp);
192 // - NEW Exponent
193 assertEquals(1, calc);
194 }
195
196 @Test
197 public void testMemberReference() {

Callers

nothing calls this directly

Calls 9

inMethod · 0.95
getAllResultsMethod · 0.95
queryMethod · 0.80
buildMethod · 0.65
getNameMethod · 0.65
sizeMethod · 0.45
getContextMethod · 0.45
getParentMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected