### Question:
OnDeployScriptBase implements OnDeployScript { protected final void searchAndUpdateResourceType(String oldResourceType, String newResourceType) throws RepositoryException { Map<String, String> map = new HashMap<>(); map.put("p.limit", "-1"); map.put("path", "/content"); map.put("1_property", SLING_RESOURCE_TYPE); map.put("1_property.value", oldResourceType); logger.info("Finding all nodes under /content with resource type: {}", oldResourceType); final CloseableQueryBuilder queryBuilder = resourceResolver.adaptTo(CloseableQueryBuilder.class); if (queryBuilder != null) { try (CloseableQuery query = queryBuilder.createQuery(PredicateGroup.create(map), session)) { SearchResult result = query.getResult(); Iterator<Node> nodeItr = result.getNodes(); if (nodeItr.hasNext()) { while (nodeItr.hasNext()) { Node node = nodeItr.next(); updateResourceType(node, newResourceType); } } else { logger.info("No nodes found with resource type: {}", oldResourceType); } } } }  final void execute(ResourceResolver resourceResolver);  }### Answer:
@Test public void testSearchAndUpdateResourceType() throws RepositoryException { Node contentRoot = resourceResolver.getResource("/content").adaptTo(Node.class); Node node1 = contentRoot.addNode("search-and-update-node1"); node1.setProperty("sling:resourceType", "mysite/type/old"); Node node2 = contentRoot.addNode("search-and-update-node2"); node2.setProperty("sling:resourceType", "mysite/type/old"); final CloseableQuery query = mock(CloseableQuery.class); SearchResult result = mock(SearchResult.class); when(result.getNodes()).thenReturn(Arrays.asList(node1, node2).iterator()); when(query.getResult()).thenReturn(result); when(queryBuilder.createQuery(any(PredicateGroup.class), any(Session.class))).then(invocation -> { PredicateGroup pg = invocation.getArgument(0); assertEquals("-1", pg.getParameters().get("limit")); assertEquals("path", pg.get(0).getType()); assertEquals("/content", pg.get(0).getParameters().get("path")); assertEquals("property", pg.get(1).getType()); assertEquals("sling:resourceType", pg.get(1).getParameters().get("property")); assertEquals("mysite/type/old", pg.get(1).getParameters().get("value")); return query; }); onDeployScript.searchAndUpdateResourceType("mysite/type/old", "mysite/type/new"); assertEquals("mysite/type/new", node1.getProperty("sling:resourceType").getString()); assertEquals("mysite/type/new", node2.getProperty("sling:resourceType").getString()); }
@Test public void testSearchAndUpdateResourceTypeWhenNoNodesFound() throws RepositoryException { CloseableQuery query = mock(CloseableQuery.class); SearchResult result = mock(SearchResult.class); when(result.getNodes()).thenReturn(Collections.EMPTY_LIST.iterator()); when(query.getResult()).thenReturn(result); when(queryBuilder.createQuery(any(PredicateGroup.class), any(Session.class))).thenReturn(query); onDeployScript.searchAndUpdateResourceType("mysite/type/old", "mysite/type/new"); assertLogText("No nodes found with resource type: mysite/type/old"); }