### Question:
DialogRewriteUtils { public static DialogType getDialogType(Node node) throws RepositoryException { DialogType type = DialogType.UNKNOWN; if (node == null) { return type; } String name = node.getName(); if (Arrays.asList(CLASSIC_DIALOG_NAMES).contains(name) && NT_DIALOG.equals(node.getPrimaryNodeType().getName())) { type = DialogType.CLASSIC; } else if (Arrays.asList(DIALOG_NAMES).contains(name) && node.hasNode("content")) { Node contentNode = node.getNode("content"); type = DialogType.CORAL_2; if (contentNode != null) { if (contentNode.hasProperty(ResourceResolver.PROPERTY_RESOURCE_TYPE)) { String resourceType = contentNode.getProperty(ResourceResolver.PROPERTY_RESOURCE_TYPE).getString(); type = resourceType.startsWith(DIALOG_CONTENT_RESOURCETYPE_PREFIX_CORAL3) ? DialogType.CORAL_3 : DialogType.CORAL_2; } } } return type; }  static boolean hasXtype(Node node, String xtype); static boolean hasType(Node node, String type); static Property copyProperty(Node source, String relPropertyPath, Node destination, String name); static DialogType getDialogType(Node node); static boolean isDesignDialog(Node node); static final String CORAL_2_BACKUP_SUFFIX; static final String NT_DIALOG; static final String NN_CQ_DIALOG; static final String NN_CQ_DESIGN_DIALOG; static final String DIALOG_CONTENT_RESOURCETYPE_PREFIX_CORAL3; }### Answer:
@Test public void testGetDialogTypeClassic() throws Exception { boolean allClassic = false; String[] classicDialogPaths = { DIALOGS_ROOT + "/classic/dialog", DIALOGS_ROOT + "/classic/design_dialog" }; for (String path: classicDialogPaths) { Resource resource = context.resourceResolver().getResource(path); Node node = resource.adaptTo(Node.class); DialogType type = DialogRewriteUtils.getDialogType(node); allClassic = (type == DialogType.CLASSIC); if (!allClassic) { break; } } assertTrue(allClassic); }
@Test public void testGetDialogTypeCoral2() throws Exception { boolean allCoral2 = false; String[] coral2DialogPaths = { DIALOGS_ROOT + "/coral2/cq:dialog", DIALOGS_ROOT + "/coral2/cq:design_dialog", DIALOGS_ROOT + "/backupsnoreplacementdiscarded/cq:dialog.coral2", DIALOGS_ROOT + "/backupsnoreplacementdiscarded/cq:design_dialog.coral2", DIALOGS_ROOT + "/level1/classicandcoral2/cq:dialog", DIALOGS_ROOT + "/level1/classicandcoral2/cq:design_dialog" }; for (String path: coral2DialogPaths) { Resource resource = context.resourceResolver().getResource(path); Node node = resource.adaptTo(Node.class); DialogType type = DialogRewriteUtils.getDialogType(node); allCoral2 = (type == DialogType.CORAL_2); if (!allCoral2) { break; } } assertTrue(allCoral2); }
@Test public void testGetDialogTypeCoral3() throws Exception { boolean allCoral3 = false; String[] coral3DialogPaths = { DIALOGS_ROOT + "/level1/converted/cq:dialog", DIALOGS_ROOT + "/level1/converted/cq:design_dialog" }; for (String path: coral3DialogPaths) { Resource resource = context.resourceResolver().getResource(path); Node node = resource.adaptTo(Node.class); DialogType type = DialogRewriteUtils.getDialogType(node); allCoral3 = (type == DialogType.CORAL_3); if (!allCoral3) { break; } } assertTrue(allCoral3); }