ConfigAdapterImpl impl = new ConfigAdapterImpl();
impl.regenerateAuraJS();
assertTrue("Framework nonce should not be empty", impl.getAuraFrameworkNonce().length() > 0);
// But an error case should fail, and not be swallowed.
final AuraJavascriptGroup mockJsGroup = mock(AuraJavascriptGroup.class);
impl = new ConfigAdapterImpl() {
@Override
public AuraJavascriptGroup newAuraJavascriptGroup() throws IOException {
return mockJsGroup;
}
@Override
public boolean isProduction() {
return false;
}
};
try {
when(mockJsGroup.isStale()).thenReturn(true);
Mockito.doThrow(new MockException("Pretend we had a compile error in regeneration")).when(mockJsGroup)
.regenerate(AuraImplFiles.AuraResourceJavascriptDirectory.asFile());
impl.regenerateAuraJS();
fail("Compilation failure should have been caught!");
} catch (AuraRuntimeException e) {
assertTrue("expected ARTE caused by MockException, not " + e.getCause().toString(),
e.getCause() instanceof MockException);
}
// Try again, without changes; it should still fail.
try {
when(mockJsGroup.isStale()).thenReturn(false);
impl.regenerateAuraJS();
fail("Second compilation failure should have been caught!");
} catch (AuraRuntimeException e2) {
assertTrue("expected ARTE caused by MockException, not " + e2.getCause().toString(),
e2.getCause() instanceof MockException);
}
// Third time's the charm, we stop pretending there are errors and it
// should work. Unless
// we're in a resources-only environment, in which case the copying done
// after our
// jsGroup.regenerate() can't work, even though the mock
// jsGroup.regenerate() will..
if (!AuraImplFiles.AuraResourceJavascriptDirectory.asFile().exists()) {
reset(mockJsGroup);
when(mockJsGroup.isStale()).thenReturn(true);
impl.regenerateAuraJS();
}
}