Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hawtjni-version>1.14</hawtjni-version>
<hawtjni-verbose>true</hawtjni-verbose>
<easymock-version>3.2</easymock-version>
<mockito-version>4.2.0</mockito-version>
<jni-with-crypto>-lcrypto</jni-with-crypto>
</properties>

Expand All @@ -30,11 +30,10 @@
<artifactId>hawtjni-runtime</artifactId>
<version>${hawtjni-version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -44,9 +43,15 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>${easymock-version}</version>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito-version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -143,6 +148,11 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
Expand Down
14 changes: 9 additions & 5 deletions src/test/java/com/github/plusvic/yara/GenericIteratorTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.github.plusvic.yara;

import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.NoSuchElementException;
import java.util.UUID;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* User: pba
Expand Down Expand Up @@ -97,7 +101,7 @@ protected String getNext() {
assertEquals(size, count);
}

@Test(expected = NoSuchElementException.class)
@Test
public void testNextFirst() {
GenericIterator<String> it = new GenericIterator<String>() {
private boolean used = false;
Expand All @@ -113,13 +117,13 @@ protected String getNext() {
};

assertNotNull(it.next());
assertNotNull(it.next());
Assertions.assertThrows(NoSuchElementException.class, it::next);
}

@Test
public void testNextFirstMultiple() {
GenericIterator<String> it = new GenericIterator<String>() {
private String values[] = new String[] { "one", "two"};
private final String[] values = new String[] { "one", "two"};
private int pos = 0;

@Override
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/com/github/plusvic/yara/UtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.github.plusvic.yara;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import static org.junit.Assert.assertEquals;

/**
* User: pba
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.github.plusvic.yara.embedded;

import com.github.plusvic.yara.*;
import com.github.plusvic.yara.TestUtils;
import com.github.plusvic.yara.YaraCompilationCallback;
import com.github.plusvic.yara.YaraCompiler;
import com.github.plusvic.yara.YaraException;
import com.github.plusvic.yara.YaraScanner;
import net.jcip.annotations.NotThreadSafe;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.nio.file.Files;
Expand All @@ -16,7 +20,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* User: pba
Expand Down Expand Up @@ -56,12 +63,13 @@ public class YaraCompilerImplTest {

private YaraImpl yara;

@Before
@BeforeEach
public void setup() {
System.out.println("assign yara");
this.yara = new YaraImpl();
}

@After
@AfterEach
public void teardown() throws Exception {
this.yara.close();
}
Expand All @@ -87,12 +95,7 @@ public void onError(ErrorLevel errorLevel, String fileName, long lineNumber, Str

@Test
public void testAddRulesContentSucceeds() throws Exception {
YaraCompilationCallback callback = new YaraCompilationCallback() {
@Override
public void onError(ErrorLevel errorLevel, String fileName, long lineNumber, String message) {
fail();
}
};
YaraCompilationCallback callback = (errorLevel, fileName, lineNumber, message) -> fail();

try (YaraCompiler compiler = yara.createCompiler()) {
compiler.setCallback(callback);
Expand All @@ -103,13 +106,9 @@ public void onError(ErrorLevel errorLevel, String fileName, long lineNumber, Str
@Test
public void testAddRulesContentFails() throws Exception {
final AtomicBoolean called = new AtomicBoolean();
YaraCompilationCallback callback = new YaraCompilationCallback() {
@Override
public void onError(ErrorLevel errorLevel, String fileName, long lineNumber, String message) {
called.set(true);
LOGGER.log(Level.INFO, String.format("Compilation failed in %s at %d: %s",
fileName, lineNumber, message));
}
YaraCompilationCallback callback = (errorLevel, fileName, lineNumber, message) -> {
called.set(true);
LOGGER.log(Level.INFO, String.format("Compilation failed in %s at %d: %s", fileName, lineNumber, message));
};

try (YaraCompiler compiler = yara.createCompiler()) {
Expand Down Expand Up @@ -235,12 +234,7 @@ public void onError(ErrorLevel errorLevel, String fileName, long lineNumber, Str

@Test
public void testCreateScanner() throws Exception {
YaraCompilationCallback callback = new YaraCompilationCallback() {
@Override
public void onError(ErrorLevel errorLevel, String fileName, long lineNumber, String message) {
fail();
}
};
YaraCompilationCallback callback = (errorLevel, fileName, lineNumber, message) -> fail();

try (YaraCompiler compiler = yara.createCompiler()) {
compiler.setCallback(callback);
Expand All @@ -252,14 +246,10 @@ public void onError(ErrorLevel errorLevel, String fileName, long lineNumber, Str
}
}

@Ignore("yara asserts which stops execution")
@Test
@Disabled("yara asserts which stops execution")
public void testAddRulesAfterScannerCreate() throws Exception {
YaraCompilationCallback callback = new YaraCompilationCallback() {
@Override
public void onError(ErrorLevel errorLevel, String fileName, long lineNumber, String message) {
fail();
}
};
YaraCompilationCallback callback = (errorLevel, fileName, lineNumber, message) -> fail();

try (YaraCompiler compiler = yara.createCompiler()) {
compiler.setCallback(callback);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.github.plusvic.yara.embedded;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import com.github.plusvic.yara.YaraCompiler;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* User: pba
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.plusvic.yara.embedded;

import net.jcip.annotations.NotThreadSafe;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;

Expand Down
Loading