verify(mockGeneratorContext).tryCreateResource(testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap");
verify(mockGeneratorContext).commitResource(testLogger, mockOutputStream);
}
public void testOutputCssMapArtifactWithTestData() throws UnableToCompleteException {
UnitTestTreeLogger testLogger = new UnitTestTreeLogger.Builder().createLogger();
ResourceContext mockResourceContext = mock(ResourceContext.class);
JMethod mockJMethod1 = mock(JMethod.class);
JMethod mockJMethod2 = mock(JMethod.class);
JMethod mockJMethod3 = mock(JMethod.class);
JClassType mockJClassType1 = mock(JClassType.class);
JClassType mockJClassType2 = mock(JClassType.class);
JClassType mockJClassType3 = mock(JClassType.class);
Map<JMethod, String> testMap = new LinkedHashMap<JMethod, String>();
testMap.put(mockJMethod1, "TESTCSSNAME1");
testMap.put(mockJMethod2, "TESTCSSNAME2");
testMap.put(mockJMethod3, "TESTCSSNAME3");
ByteArrayOutputStream testOutputStream = new ByteArrayOutputStream();
GeneratorContext mockGeneratorContext = mock(GeneratorContext.class);
GeneratedResource mockGeneratedResource = mock(GeneratedResource.class);
when(mockResourceContext.getGeneratorContext()).thenReturn(mockGeneratorContext);
when(mockGeneratorContext.tryCreateResource(
testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap")).thenReturn(testOutputStream);
when(mockJMethod1.getEnclosingType()).thenReturn(mockJClassType1);
when(mockJClassType1.getQualifiedSourceName()).thenReturn("test.class.type.1");
when(mockJMethod1.getName()).thenReturn("basename1");
when(mockJMethod2.getEnclosingType()).thenReturn(mockJClassType2);
when(mockJClassType2.getQualifiedSourceName()).thenReturn("test.class.type.2");
when(mockJMethod2.getName()).thenReturn("basename2");
when(mockJMethod3.getEnclosingType()).thenReturn(mockJClassType3);
when(mockJClassType3.getQualifiedSourceName()).thenReturn("test.class.type.3");
when(mockJMethod3.getName()).thenReturn("basename3");
when(mockGeneratorContext.commitResource(testLogger, testOutputStream)).thenReturn(
mockGeneratedResource);
JMethod method = mock(JMethod.class);
JClassType bundleType = mock(JClassType.class);
when(method.getEnclosingType()).thenReturn(bundleType);
when(bundleType.getQualifiedSourceName()).thenReturn("com.test.Bundle");
when(method.getName()).thenReturn("cssMethod");
CssResourceGenerator crg = new CssResourceGenerator();
crg.outputCssMapArtifact(testLogger, mockResourceContext, method, testMap);
String expectedOutput = "test-class-type-1-basename1,TESTCSSNAME1\n" +
"test-class-type-2-basename2,TESTCSSNAME2\n" +
"test-class-type-3-basename3,TESTCSSNAME3\n";
assertEquals(expectedOutput, testOutputStream.toString());
testLogger.assertCorrectLogEntries();
verify(mockGeneratorContext).tryCreateResource(testLogger, "cssResource/com.test.Bundle.cssMethod.cssmap");
verify(mockGeneratorContext).commitResource(testLogger, testOutputStream);
}