package org.jcae.opencascade.jni;

import static org.junit.Assert.*;
import org.junit.Test;

import java.util.HashSet;
import org.hamcrest.core.IsInstanceOf;

public class Explorer
{
	@Test public void explorer()
	{
		// Create a cube
		double[] pt1=new double[]{0,0,0};
		double[] pt2=new double[]{1,3,2};
		TopoDS_Shape box = new BRepPrimAPI_MakeBox(pt1, pt2).shape();
		
		// The created shape is a solid.
		assertThat(box, new IsInstanceOf(TopoDS_Solid.class));
		
		// Display the child of our box
		TopoDS_Iterator it=new TopoDS_Iterator(box);
		
		// The first (and only) child is a shell
		TopoDS_Shell shell=(TopoDS_Shell) it.value();
		it.next();
		assertFalse(it.more());
		
		// Children of the shell are faces
		it=new TopoDS_Iterator(shell);
		while(it.more())
		{
			assertThat(it.value(), new IsInstanceOf(TopoDS_Face.class));
			it.next();
		}
		
		// TopExp_Explorer is easier to use if you are looking for shapes
		// of a give type. Let's count the number of edges in the box
		TopExp_Explorer exp=new TopExp_Explorer(box, TopAbs_ShapeEnum.EDGE);
		int counter=0;
		HashSet<TopoDS_Shape> set=new HashSet<TopoDS_Shape>();
		while(exp.more())
		{
			//Just to show that the type is TopoDS_Edge
			assertThat(exp.current(), new IsInstanceOf(TopoDS_Edge.class));
			set.add(exp.current());
			
			counter++;
			exp.next();
		}
		
		// the number of edges is 24 because each edge is shared by 2
		// faces.
		assertTrue(counter == 24);

		// the number of edges is 12
		assertTrue(12 == set.size());
	}
}

@@ -115,47 +115,8 @@
 Set;
-%0Aimport org.hamcrest.core.IsInstanceOf;
 %0A%0Apu
@@ -376,34 +376,27 @@
 ertT
-hat
+rue
 (box
-, new IsI
+ i
 nstance
-Of(
+of 
 Topo
@@ -403,23 +403,16 @@
 DS_Solid
-.class)
 );%0A%09%09%0A%09%09
@@ -729,19 +729,19 @@
 %09assertT
-hat
+rue
 (it.valu
@@ -743,35 +743,28 @@
 .value()
-, new IsI
+ i
 nstance
-Of(
+of 
 TopoDS_F
@@ -766,23 +766,16 @@
 oDS_Face
-.class)
 );%0A%09%09%09it
@@ -1148,19 +1148,19 @@
 %09assertT
-hat
+rue
 (exp.cur
@@ -1169,27 +1169,20 @@
 nt()
-, new IsI
+ i
 nstance
-Of(
+of 
 Topo
@@ -1192,15 +1192,8 @@
 Edge
-.class)
 );%0A%09

assertThat has been introduced in JUnit 4.5, replace it by assertTrue