### Question:
NamedClusterEmbedManager { public void registerUrl( String urlString ) { if ( urlString == null || addedAllClusters == true ) { return; } if ( urlString.startsWith( VARIABLE_START ) ) { addAllClusters(); } Pattern r = Pattern.compile( URL_PATTERN ); Matcher m = r.matcher( urlString ); if ( m.find() ) { String protocol = m.group( PARSE_URL_SCHEME ); String clusterName = m.group( PARSE_URL_AUTHORITY ); if ( "hc".equals( protocol ) ) { if ( clusterName.startsWith( VARIABLE_START ) ) { addAllClusters(); } addClusterToMeta( clusterName ); } } } NamedClusterEmbedManager( AbstractMeta meta, LogChannelInterface log ); void registerUrl( String urlString ); void clear(); boolean isAddedAnyClusters(); void addClusterToMeta( String clusterName ); void passEmbeddedMetastoreKey( VariableSpace nameSpace, String embeddedMetastoreProviderKey ); static final String NAMESPACE; }### Answer:
@Test public void testRegisterUrlNc() throws Exception { namedClusterEmbedManager.registerUrl( "hc: verify( mockMetaStoreFactory ).saveElement( mockNamedCluster1 ); }
@Test public void testRegisterUrlNotNc() throws Exception { namedClusterEmbedManager.registerUrl( "hdfs: verify( mockMetaStoreFactory, never() ).saveElement( any() ); }
@Test public void testRegisterUrlRegularFile() throws Exception { namedClusterEmbedManager.registerUrl( "/" + CLUSTER1_NAME + "/dir1/dir2" ); verify( mockMetaStoreFactory, never() ).saveElement( any() ); }
@Test public void testRegisterUrlFullVariable() throws Exception { when( mockNamedClusterService.listNames( mockMeta.getMetaStore() ) ) .thenReturn( Arrays.asList( new String[] { CLUSTER1_NAME, CLUSTER2_NAME } ) ); namedClusterEmbedManager.registerUrl( "${variable)" ); verify( mockMetaStoreFactory ).saveElement( mockNamedCluster1 ); verify( mockMetaStoreFactory ).saveElement( mockNamedCluster2 ); }
@Test public void testRegisterUrlClusterVariable() throws Exception { when( mockNamedClusterService.listNames( mockMeta.getMetaStore() ) ) .thenReturn( Arrays.asList( new String[] { CLUSTER1_NAME, CLUSTER2_NAME } ) ); namedClusterEmbedManager.registerUrl( "hc: verify( mockMetaStoreFactory ).saveElement( mockNamedCluster1 ); verify( mockMetaStoreFactory ).saveElement( mockNamedCluster2 ); }
@Test public void testRegisterUrlAlreadyRegistered() throws Exception { when( mockMetaStoreFactory.loadElement( CLUSTER1_NAME ) ).thenReturn( mockNamedCluster1 ); namedClusterEmbedManager.registerUrl( "hc: verify( mockMetaStoreFactory, times(0 ) ).saveElement( mockNamedCluster1 ); }
@Test public void testRegisterUrlAlreadyRegistered() throws Exception { when( mockMetaStoreFactory.loadElement( CLUSTER1_NAME ) ).thenReturn( mockNamedCluster1 ); namedClusterEmbedManager.registerUrl( "hc: verify( mockMetaStoreFactory, times( 0 ) ).saveElement( mockNamedCluster1 ); }