public Sandwich() { super(); // Compiler adds it if it is not explicitly added by programmer // All the instance variable initialization is moved here by the compiler. b = new Bread(); c = new Cheese(); l = new Lettuce(); System.out.println("Sandwich()"); }
public void assertNotContains (final Object obj, final Collection collection) { try { assertContains( obj, collection); fail( collection + " does not contain " + obj ); } catch(Throwable t) { // do nothing as this is assertion is ok } }
@Test public void updateWithDifferentClassGetObjectsTest() { final Person person = new Person("George", 18); final FactHandle factPerson = ksession.insert(person); final Person personToBeVerified = verifyFactsPresentInSession(1, Person.class).get(0); assertThat(personToBeVerified).isEqualTo(person); final Cheese cheese = new Cheese("Camembert", 50); ksession.update(factPerson, cheese); verifyFactsPresentInSession(1, Cheese.class); final Cheese cheeseToBeVerified = (Cheese) ksession.getObjects().iterator().next(); verifyCheese(cheeseToBeVerified, 50, "Camembert"); }
private void verifyPerson(final Person original, final Person personToBeVerified, final int age, final String name, final boolean shouldBeEqual) { if (original != null) { if (shouldBeEqual) { assertThat(personToBeVerified).isEqualTo(original); } else { assertThat(personToBeVerified).isNotEqualTo(original); } } assertThat(personToBeVerified.getAge()).isEqualTo(age); assertThat(personToBeVerified.getName()).isEqualTo(name); }
@Test(expected = NullPointerException.class) public void updateWithNullTest() { final Person person = new Person("George", 18); final FactHandle factPerson = ksession.insert(person); verifyFactsPresentInSession(1, Person.class); ksession.update(factPerson, null); }
@Test public void testAddActivation() { guard.addActivation(new MockActivation()); assertThat(guard.getActivations()).isNotEmpty(); assertThat(guard.getActivations()).hasSize(1); guard.addActivation(new MockActivation()); guard.addActivation(new MockActivation()); guard.addActivation(new MockActivation()); assertThat(guard.getActivations()).hasSize(4); }
public void run() { try { final int ITERATIONS = 300; for ( int k = 0; k < ITERATIONS; k++ ) { String value = (String) extractor.getValue( null, person[ID % 2] ); if ( !home[ID % 2].getStreet().equals( value ) ) { errors.add( "THREAD(" + ID + "): Wrong value at iteration " + k + ". Value='" + value + "'\n" ); } } } catch ( Exception ex ) { ex.printStackTrace(); errors.add( ex ); } }
public Consequence getConsequence() { return getRule().getConsequence(); }
@Test public void testObjectIterator() { InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(); KieSession ksession = kBase.newKieSession(); ksession.insert( new Person( "bob", 35) ); ksession.insert( new Cheese( "stilton", 35) ); ksession.insert( new Cheese( "brie", 35) ); ksession.insert( new Person( "steve", 55) ); ksession.insert( new Person( "tom", 100) ); int i = 0; for ( FactHandle fh : ksession.getFactHandles()) { if ( i++ > 5 ) { fail( "should not iterate for than 3 times" ); } } i = 0; for ( FactHandle fh : ksession.getFactHandles()) { if ( i++ > 5 ) { fail( "should not iterate for than 3 times" ); } } }
private Bread b = new Bread(); private Cheese c = new Cheese(); private Lettuce l = new Lettuce();
@Test public void testIsActive() { final Activation activation = new MockActivation(); guard.addActivation(activation); assertThat(guard.isActive()).isTrue(); guard.removeActivation(activation); assertThat(guard.isActive()).isFalse(); }
public void assertNotContains (final Object obj, final Object[] array) { try { assertContains( obj, array); fail( Arrays.asList( array ) + " contains " + obj ); } catch(Throwable t) { // do nothing as this is assertion is ok } }
@Test public void testGetValue() { try { assertEquals( home[0].getStreet(), this.extractor.getValue( null, this.person[0] ) ); assertTrue( this.extractor.getValue( null, this.person[0] ) instanceof String ); } catch ( final Exception e ) { fail( "Should not throw an exception" ); } }
@Test public void deleteUpdatedFactDifferentClassTest() { FactHandle fact = ksession.insert(new Person("George", 18)); Assertions.assertThat(ksession.getObjects()).hasSize(1); Assertions.assertThat(ksession.getObjects().iterator().next()).isInstanceOf(Person.class); ksession.update(fact, new Cheese("Cheddar", 50)); Assertions.assertThat(ksession.getObjects()).hasSize(1); Assertions.assertThat(ksession.getObjects().iterator().next()).isInstanceOf(Cheese.class); ksession.delete(fact); Assertions.assertThat(ksession.getObjects()).isEmpty(); }
@Test public void testEmptyIterator() { final TupleList map = new TupleList(); final Cheese stilton1 = new Cheese( "stilton", 35 ); final InternalFactHandle h1 = new DefaultFactHandle( 1, stilton1 ); assertNull( map.getFirst( new LeftTupleImpl( h1, null, true ) ) ); } }
@Test public void testRemoveActivation() { final Activation activation = new MockActivation(); guard.addActivation(activation); assertThat(guard.getActivations()).isNotEmpty(); guard.removeActivation(activation); assertThat(guard.getActivations()).isEmpty(); }
@Test public void updateWithDifferentClassGetQueryResultsTest() { final Person person = new Person("George", 18); final FactHandle fact = ksession.insert(person); verifyFactsWithQuery(Person.class, "persons", person); final Cheese cheese = new Cheese("Camembert", 2); ksession.update(fact, cheese); verifyWithQueryNoPersonsPresentInFacts(); verifyFactsPresentInSession(1, Cheese.class); Cheese cheeseToBeVerified = (Cheese) ksession.getObjects().iterator().next(); verifyCheese(cheeseToBeVerified, 2, "Camembert"); cheeseToBeVerified = verifyFactPresentInSession(fact, Cheese.class); verifyCheese(cheeseToBeVerified, 2, "Camembert"); }
@Test public void testDeclarationsObjectType() throws Exception { final ObjectType type = new ClassObjectType( Cheese.class ); final Pattern col = new Pattern( 0, type, "foo" ); final Declaration dec = col.getDeclaration(); final InternalReadAccessor ext = dec.getExtractor(); assertEquals( Cheese.class, ext.getExtractToClass() ); final Cheese stilton = new Cheese( "stilton", 42 ); assertEquals( stilton, dec.getValue( null, stilton ) ); }