|  | @@ -8,9 +8,13 @@ import com.reactnativenavigation.BaseTest;
 | 
	
		
			
			| 8 | 8 |  import com.reactnativenavigation.mocks.SimpleViewController;
 | 
	
		
			
			| 9 | 9 |  import com.reactnativenavigation.mocks.TestStackAnimator;
 | 
	
		
			
			| 10 | 10 |  
 | 
	
		
			
			|  | 11 | +import org.assertj.core.api.iterable.Extractor;
 | 
	
		
			
			| 11 | 12 |  import org.junit.Test;
 | 
	
		
			
			| 12 | 13 |  
 | 
	
		
			
			| 13 | 14 |  import static org.assertj.core.api.Java6Assertions.assertThat;
 | 
	
		
			
			|  | 15 | +import static org.mockito.Mockito.spy;
 | 
	
		
			
			|  | 16 | +import static org.mockito.Mockito.times;
 | 
	
		
			
			|  | 17 | +import static org.mockito.Mockito.verify;
 | 
	
		
			
			| 14 | 18 |  
 | 
	
		
			
			| 15 | 19 |  public class StackControllerTest extends BaseTest {
 | 
	
		
			
			| 16 | 20 |  
 | 
	
	
		
			
			|  | @@ -175,11 +179,6 @@ public class StackControllerTest extends BaseTest {
 | 
	
		
			
			| 175 | 179 |  		assertHasSingleChildViewOfController(child2);
 | 
	
		
			
			| 176 | 180 |  	}
 | 
	
		
			
			| 177 | 181 |  
 | 
	
		
			
			| 178 |  | -	@Test
 | 
	
		
			
			| 179 |  | -	public void getStackControllerReturnsSelf() throws Exception {
 | 
	
		
			
			| 180 |  | -		assertThat(uut.getParentStackController()).isEqualTo(uut);
 | 
	
		
			
			| 181 |  | -	}
 | 
	
		
			
			| 182 |  | -
 | 
	
		
			
			| 183 | 182 |  	@Test
 | 
	
		
			
			| 184 | 183 |  	public void popTo_PopsTopUntilControllerIsNewTop() throws Exception {
 | 
	
		
			
			| 185 | 184 |  		uut.push(child1);
 | 
	
	
		
			
			|  | @@ -242,6 +241,50 @@ public class StackControllerTest extends BaseTest {
 | 
	
		
			
			| 242 | 241 |  		assertThat(uut.findControllerById(child2.getId())).isEqualTo(child2);
 | 
	
		
			
			| 243 | 242 |  	}
 | 
	
		
			
			| 244 | 243 |  
 | 
	
		
			
			|  | 244 | +	@Test
 | 
	
		
			
			|  | 245 | +	public void pop_CallsDestroyOnPoppedChild() throws Exception {
 | 
	
		
			
			|  | 246 | +		child1 = spy(child1);
 | 
	
		
			
			|  | 247 | +		child2 = spy(child2);
 | 
	
		
			
			|  | 248 | +		child3 = spy(child3);
 | 
	
		
			
			|  | 249 | +		uut.push(child1);
 | 
	
		
			
			|  | 250 | +		uut.push(child2);
 | 
	
		
			
			|  | 251 | +		uut.push(child3);
 | 
	
		
			
			|  | 252 | +
 | 
	
		
			
			|  | 253 | +		verify(child3, times(0)).destroy();
 | 
	
		
			
			|  | 254 | +		uut.pop();
 | 
	
		
			
			|  | 255 | +		verify(child3, times(1)).destroy();
 | 
	
		
			
			|  | 256 | +	}
 | 
	
		
			
			|  | 257 | +
 | 
	
		
			
			|  | 258 | +	@Test
 | 
	
		
			
			|  | 259 | +	public void popSpecific_CallsDestroyOnPoppedChild() throws Exception {
 | 
	
		
			
			|  | 260 | +		child1 = spy(child1);
 | 
	
		
			
			|  | 261 | +		child2 = spy(child2);
 | 
	
		
			
			|  | 262 | +		child3 = spy(child3);
 | 
	
		
			
			|  | 263 | +		uut.push(child1);
 | 
	
		
			
			|  | 264 | +		uut.push(child2);
 | 
	
		
			
			|  | 265 | +		uut.push(child3);
 | 
	
		
			
			|  | 266 | +
 | 
	
		
			
			|  | 267 | +		verify(child2, times(0)).destroy();
 | 
	
		
			
			|  | 268 | +		uut.popSpecific(child2);
 | 
	
		
			
			|  | 269 | +		verify(child2, times(1)).destroy();
 | 
	
		
			
			|  | 270 | +	}
 | 
	
		
			
			|  | 271 | +
 | 
	
		
			
			|  | 272 | +	@Test
 | 
	
		
			
			|  | 273 | +	public void popTo_CallsDestroyOnPoppedChild() throws Exception {
 | 
	
		
			
			|  | 274 | +		child1 = spy(child1);
 | 
	
		
			
			|  | 275 | +		child2 = spy(child2);
 | 
	
		
			
			|  | 276 | +		child3 = spy(child3);
 | 
	
		
			
			|  | 277 | +		uut.push(child1);
 | 
	
		
			
			|  | 278 | +		uut.push(child2);
 | 
	
		
			
			|  | 279 | +		uut.push(child3);
 | 
	
		
			
			|  | 280 | +
 | 
	
		
			
			|  | 281 | +		verify(child2, times(0)).destroy();
 | 
	
		
			
			|  | 282 | +		verify(child3, times(0)).destroy();
 | 
	
		
			
			|  | 283 | +		uut.popTo(child1);
 | 
	
		
			
			|  | 284 | +		verify(child2, times(1)).destroy();
 | 
	
		
			
			|  | 285 | +		verify(child3, times(1)).destroy();
 | 
	
		
			
			|  | 286 | +	}
 | 
	
		
			
			|  | 287 | +
 | 
	
		
			
			| 245 | 288 |  	private void assertHasSingleChildViewOfController(ViewController childController) {
 | 
	
		
			
			| 246 | 289 |  		assertThat(uut.getView().getChildCount()).isEqualTo(1);
 | 
	
		
			
			| 247 | 290 |  		assertThat(uut.getView().getChildAt(0)).isEqualTo(childController.getView());
 | 
	
	
		
			
			|  | @@ -249,8 +292,11 @@ public class StackControllerTest extends BaseTest {
 | 
	
		
			
			| 249 | 292 |  
 | 
	
		
			
			| 250 | 293 |  	private void assertContainsOnlyId(String... ids) {
 | 
	
		
			
			| 251 | 294 |  		assertThat(uut.size()).isEqualTo(ids.length);
 | 
	
		
			
			| 252 |  | -		for (String id : ids) {
 | 
	
		
			
			| 253 |  | -			assertThat(uut.containsId(id));
 | 
	
		
			
			| 254 |  | -		}
 | 
	
		
			
			|  | 295 | +		assertThat(uut.getChildControllers()).extracting(new Extractor<ViewController, String>() {
 | 
	
		
			
			|  | 296 | +			@Override
 | 
	
		
			
			|  | 297 | +			public String extract(final ViewController input) {
 | 
	
		
			
			|  | 298 | +				return input.getId();
 | 
	
		
			
			|  | 299 | +			}
 | 
	
		
			
			|  | 300 | +		}).containsOnly(ids);
 | 
	
		
			
			| 255 | 301 |  	}
 | 
	
		
			
			| 256 | 302 |  }
 |