### Question:
SystemDataSourceNameProvider { public String getDataSourceName() { if(dataSourceName == null) { dataSourceName = format(SYSTEM_JNDI_PATTERN, contextName()); } return dataSourceName; }  String getDataSourceName();  }### Answer:
@Test public void shouldCorrectlyGenerateTheCorrectDataSourceNameBasedOnTheAppName() throws Exception { when(jndiAppNameProvider.getAppName()).thenReturn("framework"); assertThat(systemDataSourceNameProvider.getDataSourceName(), is("java:/app/framework/DS.system")); }
@Test public void shouldIgnoreAnyPartOfTheAppNameAfterAHyphen() throws Exception { when(jndiAppNameProvider.getAppName()).thenReturn("framework-context-with-hyphens"); assertThat(systemDataSourceNameProvider.getDataSourceName(), is("java:/app/framework/DS.system")); }
@Test public void shouldOnlyGenerateTheNameOnce() throws Exception { when(jndiAppNameProvider.getAppName()).thenReturn("framework"); systemDataSourceNameProvider.getDataSourceName(); systemDataSourceNameProvider.getDataSourceName(); systemDataSourceNameProvider.getDataSourceName(); systemDataSourceNameProvider.getDataSourceName(); systemDataSourceNameProvider.getDataSourceName(); systemDataSourceNameProvider.getDataSourceName(); systemDataSourceNameProvider.getDataSourceName(); verify(jndiAppNameProvider, times(1)).getAppName(); }