	@Test
	public void testComplexCssAndJsHierarchy() {

		ClientLibrary clientLibraryA =  new MockClientLibraryBuilder(MockClientLibraryBuilder.MockClientLibraryType.CSS, "categoryA").getClientLibrary();
		ClientLibrary clientLibraryB = new MockClientLibraryBuilder(MockClientLibraryBuilder.MockClientLibraryType.JSANDCSS, "categoryB").setDependentLibraries(clientLibraryA).getClientLibrary();
		ClientLibrary clientLibraryC = new MockClientLibraryBuilder(MockClientLibraryBuilder.MockClientLibraryType.JS, "categoryC").setDependentLibraries(clientLibraryB).getClientLibrary();
		ClientLibrary clientLibraryD =  new MockClientLibraryBuilder(MockClientLibraryBuilder.MockClientLibraryType.JSANDCSS, "categoryD").setEmbeddedCssLibraries(clientLibraryA).getClientLibrary();
		ClientLibrary clientLibraryE = new MockClientLibraryBuilder(MockClientLibraryBuilder.MockClientLibraryType.JSANDCSS, "categoryE").setDependentLibraries(clientLibraryD).setEmbeddedJsLibraries(clientLibraryC).getClientLibrary();
		
		List<String> allCategories = new ArrayList<String>();
		ClientLibOptimizerServlet.getSortedDependentCategories(Collections.singleton(clientLibraryE), Collections.singleton("categoryE"), LibraryType.JS, allCategories);
		Assert.assertThat(allCategories, Matchers.contains("categoryD", "categoryB", "categoryC", "categoryE"));
		
		allCategories.clear();
		ClientLibOptimizerServlet.getSortedDependentCategories(Collections.singleton(clientLibraryE), Collections.singleton("categoryE"), LibraryType.CSS, allCategories);
		Assert.assertThat(allCategories, Matchers.contains("categoryA","categoryD","categoryB","categoryE"));
	}