Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michbarsinai committed Mar 21, 2017
1 parent d7a4983 commit 697c6bc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public SingleResourceBProgram(String aResourceName) {
URL resUrl = Thread.currentThread().getContextClassLoader().getResource(aResourceName);

if ( resUrl == null ) {
throw new RuntimeException( "Cannot find resource '" + aResourceName + "'");
throw new IllegalArgumentException( "Cannot find resource '" + aResourceName + "'");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected void setupProgramScope(Scriptable scope) {
fail("System should have thrown an error due to bsync called outside of a BThread.");
} catch (BPjsCodeEvaluationException exp) {
assertEquals( 3, exp.getLineNumber() );
assertEquals( "hardcoded", exp.getSourceName() );
assertTrue( exp.getMessage().contains("bsync"));
assertTrue( exp.getMessage().contains("Did you forget")); // make sure this is the friendly message
assertEquals(1, exp.getScriptStackTrace().size());
Expand All @@ -38,7 +39,7 @@ public void testInvalidJavascript() throws InterruptedException {
@Override
protected void setupProgramScope(Scriptable scope) {
evaluate("var j=9\n"
+ "I'm not a Javascript code at all.\n"
+ "#This isn't a javascript line.\n"
+ "var o=0;",
"hardcoded");
}
Expand All @@ -49,6 +50,9 @@ protected void setupProgramScope(Scriptable scope) {
fail("System should have thrown an error due to uncompilable Javascript code.");
} catch (BPjsCodeEvaluationException exp) {
assertEquals( 2, exp.getLineNumber() );
assertEquals( 1, exp.getColumnNumber() );
assertEquals("#This isn't a javascript line.", exp.getLineSource());

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class NoBSyncTest {

@Test
public void test() throws InterruptedException {
BProgram sut = new SingleResourceBProgram("noBSyncs.js");
BProgram sut = new SingleResourceBProgram("noBSyncs.js", "noBSyncs");

sut.start();
final Long actualValue = sut.getFromGlobalScope("shouldBe7", Long.class).get();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* The MIT License
*
* Copyright 2017 michael.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine;

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

/**
*
* @author michael
*/
public class SingleResourceBProgramTest {

@Test
public void testMissingResource() {
final String missingResourceName = "I'm not there";
try {
new SingleResourceBProgram(missingResourceName);
} catch ( IllegalArgumentException iae ) {
assertTrue(iae.getMessage().contains(missingResourceName));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.listeners.InMemoryEventLoggingListener;
import il.ac.bgu.cs.bp.bpjs.bprogram.runtimeengine.listeners.StreamLoggerListener;
import il.ac.bgu.cs.bp.bpjs.events.BEvent;
import il.ac.bgu.cs.bp.bpjs.eventselection.SimpleEventSelectionStrategy;
import java.util.Arrays;
import static java.util.stream.Collectors.toList;
import static org.junit.Assert.assertEquals;
Expand All @@ -21,14 +22,14 @@ public class EventsWithDataTest {

@Test
public void testEventsWithData() throws Exception {
BProgram bpr = new SingleResourceBProgram( "EventsWithData.js" );
BProgram bpr = new SingleResourceBProgram( "EventsWithData.js", "programName", new SimpleEventSelectionStrategy(99l) );
bpr.addListener( new StreamLoggerListener() );
InMemoryEventLoggingListener events = bpr.addListener( new InMemoryEventLoggingListener() );

bpr.start();

assertEquals( Arrays.asList("e1", "e2", "e1e2"),
events.getEvents().stream().map( BEvent::getName).collect(toList()));
events.getEvents().stream().map( BEvent::getName).collect(toList()) );

}

Expand Down

0 comments on commit 697c6bc

Please sign in to comment.