Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gmerr3 committed Nov 5, 2024
1 parent 8ff9ea1 commit 3ec9d29
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/test/java/org/checkerframework/specimin/BuiltinEnumTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.checkerframework.specimin;

import java.io.IOException;
import org.junit.Test;

/** This test checks if Specimin is able to process Java builtin enum classes. Issue #361 */
public class BuiltinEnumTest {
@Test
public void runTest() throws IOException {
SpeciminTestExecutor.runTestWithoutJarPaths(
"enumbuiltin",
new String[] {"com/example/Scheduler.java"},
new String[] {"com.example.Scheduler#schedule(Runnable, int)"});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.checkerframework.specimin;

import java.io.IOException;
import org.junit.Test;

/**
* This test checks if Specimin correctly preserves things that are used as arguments to enum
* constants.
*/
public class DefaultPackageTest {
@Test
public void runTest() throws IOException {
SpeciminTestExecutor.runTestWithoutJarPaths(
"defaultpackage", new String[] {"A.java"}, new String[] {"A#schedule(Runnable, int)"});
}
}
32 changes: 32 additions & 0 deletions src/test/java/org/checkerframework/specimin/Issue368Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.checkerframework.specimin;

import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import org.junit.Test;

/**
* This test is the test described in <a
* href="https://github.com/njit-jerse/specimin/issues/368">...</a>. The issue caused the original
* source file A.java to be deleted, and in addition not appear in the output.
*/
public class Issue368Test {
@Test
public void runTest() throws IOException {
Path fileASource = Path.of("src/test/resources/issue368/A_code.java");
Path fileAPath = Path.of("src/test/resources/issue368/input/com/example/A.java");
Files.copy(fileASource, fileAPath, StandardCopyOption.REPLACE_EXISTING);
String fileACode = Files.readString(fileAPath);
SpeciminTestExecutor.runTestWithoutJarPaths(
"issue368", new String[] {"com/example/B.java"}, new String[] {"com.example.B#test()"});

try {
assertTrue(Files.exists(fileAPath));
} finally {
Files.writeString(fileAPath, fileACode);
}
}
}
6 changes: 6 additions & 0 deletions src/test/resources/defaultpackage/expected/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public class A {

public static void schedule(Runnable task, int millis) {
System.out.println();
}
}
5 changes: 5 additions & 0 deletions src/test/resources/defaultpackage/input/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class A{//no package declaration
public static void schedule(Runnable task, int millis) {
System.out.println();
}
}
13 changes: 13 additions & 0 deletions src/test/resources/enumbuiltin/expected/com/example/Scheduler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Scheduler {

public static final ScheduledExecutorService ses = null;

public static void schedule(Runnable task, int millis) {
ses.schedule(task, millis, TimeUnit.MILLISECONDS);
}
}
14 changes: 14 additions & 0 deletions src/test/resources/enumbuiltin/input/com/example/Scheduler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Scheduler{
private Scheduler() {}
public static final ScheduledExecutorService ses=newSingleThreadScheduledExecutor(r->new Thread(r,"Scheduler thread"));

public static void schedule(Runnable task, int millis) {
ses.schedule(task,millis,TimeUnit.MILLISECONDS);
}
}
21 changes: 21 additions & 0 deletions src/test/resources/issue368/A_code.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.AsynchronousSocketChannel;

public class A{
public AsynchronousSocketChannel client;
public A(AsynchronousSocketChannel client){
this.client=client;
}
public InetAddress test(){//target method
try {
if(client.getRemoteAddress() instanceof InetSocketAddress isa)
return isa.getAddress();
} catch (IOException e) {

}
return null;
}
}
10 changes: 10 additions & 0 deletions src/test/resources/issue368/expected/com/example/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example;

import java.net.InetAddress;

public class A {

public InetAddress test() {
throw new Error();
}
}
10 changes: 10 additions & 0 deletions src/test/resources/issue368/expected/com/example/B.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example;

import java.net.InetAddress;

public class B extends A {

public InetAddress test() {
return super.test();
}
}
21 changes: 21 additions & 0 deletions src/test/resources/issue368/input/com/example/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.AsynchronousSocketChannel;

public class A{
public AsynchronousSocketChannel client;
public A(AsynchronousSocketChannel client){
this.client=client;
}
public InetAddress test(){//target method
try {
if(client.getRemoteAddress() instanceof InetSocketAddress isa)
return isa.getAddress();
} catch (IOException e) {

}
return null;
}
}
11 changes: 11 additions & 0 deletions src/test/resources/issue368/input/com/example/B.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example;
import java.io.IOException;
import java.net.InetAddress;

public class B extends A {

@Override
public InetAddress test(){
return super.test();
}
}

0 comments on commit 3ec9d29

Please sign in to comment.