Skip to content

Commit

Permalink
Merge pull request #4 from dylibso/remove-mocking
Browse files Browse the repository at this point in the history
Remove Mocking dependency, plus minor pom.xml refactoring
  • Loading branch information
bhelx authored Sep 25, 2023
2 parents 0aeef02 + beda90d commit 8e89de3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 23 deletions.
31 changes: 17 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit.version>4.13.1</junit.version>
<spotless.version>2.39.0</spotless.version>
</properties>

Expand All @@ -28,20 +29,22 @@
<module>runtime</module>
</modules>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.dylibso.chickory</groupId>
<artifactId>wasm</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
Expand Down
6 changes: 5 additions & 1 deletion runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
<dependency>
<groupId>com.dylibso.chickory</groupId>
<artifactId>wasm</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
31 changes: 23 additions & 8 deletions runtime/src/test/java/com/dylibso/chicory/runtime/ModuleTest.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
package com.dylibso.chicory.runtime;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.*;

import com.dylibso.chicory.wasm.types.Value;
import com.dylibso.chicory.wasm.types.ValueType;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.*;

class Printer {

private int count = 0;
private final String expected;

Printer() {
this.expected = null;
}
Printer(String expected) {
this.expected = expected;
}
public void println(String msg) {
if (expected == null || expected.equals(msg)) {
count++;
}
System.out.println(msg);
}

public int times() {
return count;
}
}

public class ModuleTest
Expand Down Expand Up @@ -70,7 +85,7 @@ public void shouldExerciseBranches() {

@Test
public void shouldConsoleLogWithString() {
var printer = mock(Printer.class);
var printer = new Printer("Hello, World!");
var func = new HostFunction(
(Memory memory, Value... args) -> {
var offset = args[0].asInt();
Expand All @@ -88,7 +103,7 @@ public void shouldConsoleLogWithString() {
var instance = Module.build("src/test/resources/wasm/host-function.wat.wasm").instantiate(funcs);
var logIt = instance.getExport("logIt");
logIt.apply();
verify(printer, times(10)).println("Hello, World!");
assertEquals(10, printer.times());
}


Expand Down Expand Up @@ -116,7 +131,7 @@ private static long factorial(int number) {

@Test
public void shouldWorkWithStartFunction() {
var printer = mock(Printer.class);
var printer = new Printer("gotit 42");
var func = new HostFunction(
(Memory memory, Value... args) -> {
var val = args[0];
Expand All @@ -132,7 +147,7 @@ public void shouldWorkWithStartFunction() {
var module = Module.build("src/test/resources/wasm/start.wat.wasm").instantiate(funcs);
var start = module.getExport("_start");
start.apply();
verify(printer, atLeastOnce()).println("gotit 42");
assertTrue(printer.times() > 0);
}


Expand Down
7 changes: 7 additions & 0 deletions wasm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
<artifactId>wasm</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

</project>

0 comments on commit 8e89de3

Please sign in to comment.