### Question:
DefaultColorThemeReferenceFactory implements ColorThemeReferenceFactory { @Override public ColorThemeReference createReference(String colorThemeName) throws LESSCompilerException { XWikiContext xcontext = xcontextProvider.get(); XWiki xwiki = xcontext.getWiki(); String currentWikiId = wikiDescriptorManager.getCurrentWikiId(); DocumentReference colorThemeDocRef = documentReferenceResolver.resolve(colorThemeName, new WikiReference(currentWikiId)); if (xwiki.exists(colorThemeDocRef, xcontext)) { try { XWikiDocument colorThemeDoc = xwiki.getDocument(colorThemeDocRef, xcontext); DocumentReference colorThemeClassRef = new DocumentReference(colorThemeDocRef.getWikiReference().getName(), "ColorThemes", "ColorThemeClass"); if (colorThemeDoc.getXObjectSize(colorThemeClassRef) > 0) { return createReference(colorThemeDocRef); } DocumentReference flamingoThemeClassRef = new DocumentReference(colorThemeDocRef.getWikiReference().getName(), "FlamingoThemesCode", "ThemeClass"); if (colorThemeDoc.getXObjectSize(flamingoThemeClassRef) > 0) { return createReference(colorThemeDocRef); } } catch (XWikiException e) { throw new LESSCompilerException(String.format("Unable to read document [%s]", colorThemeDocRef)); } } return new NamedColorThemeReference(colorThemeName); }  @Override ColorThemeReference createReference(String colorThemeName); @Override ColorThemeReference createReference(DocumentReference documentReference);  }### Answer:
@Test public void createReferenceWhenItIsAColorTheme() throws Exception { DocumentReference colorThemeDocRef = new DocumentReference("otherWiki", "ColorThemes", "colorTheme"); when(documentReferenceResolver.resolve(eq("colorTheme"), eq(new WikiReference("wikiId")))).thenReturn( colorThemeDocRef); when(xwiki.exists(colorThemeDocRef, xcontext)).thenReturn(true); XWikiDocument colorThemeDoc = mock(XWikiDocument.class); when(xwiki.getDocument(colorThemeDocRef, xcontext)).thenReturn(colorThemeDoc); when(colorThemeDoc.getXObjectSize(eq(new DocumentReference("otherWiki", "ColorThemes", "ColorThemeClass")))). thenReturn(1); assertEquals(new DocumentColorThemeReference(new DocumentReference("otherWiki", "ColorThemes", "colorTheme"), null), mocker.getComponentUnderTest().createReference("colorTheme")); }
@Test public void createReferenceWhenItIsAFlamingoTheme() throws Exception { DocumentReference colorThemeDocRef = new DocumentReference("otherWiki", "ColorThemes", "colorTheme"); when(documentReferenceResolver.resolve(eq("colorTheme"), eq(new WikiReference("wikiId")))).thenReturn( colorThemeDocRef); when(xwiki.exists(colorThemeDocRef, xcontext)).thenReturn(true); XWikiDocument colorThemeDoc = mock(XWikiDocument.class); when(xwiki.getDocument(colorThemeDocRef, xcontext)).thenReturn(colorThemeDoc); when(colorThemeDoc.getXObjectSize(eq(new DocumentReference("otherWiki", "ColorThemes", "ColorThemeClass")))). thenReturn(0); when(colorThemeDoc.getXObjectSize(eq(new DocumentReference("otherWiki", "FlamingoThemesCode", "ThemeClass")))). thenReturn(1); assertEquals(new DocumentColorThemeReference(new DocumentReference("otherWiki", "ColorThemes", "colorTheme"), null), mocker.getComponentUnderTest().createReference("colorTheme")); }
@Test public void createReferenceWhenItIsDefault() throws Exception { DocumentReference colorThemeDocRef = new DocumentReference("wikiId", "Main", "default"); when(documentReferenceResolver.resolve("default")).thenReturn(colorThemeDocRef); when(xwiki.exists(colorThemeDocRef, xcontext)).thenReturn(false); assertEquals(new NamedColorThemeReference("default"), mocker.getComponentUnderTest().createReference("default")); }