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