Skip to content

Commit

Permalink
Migrate to Junit and assertJ
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Aug 11, 2024
1 parent 6d7711c commit 5f9e2af
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 140 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/io/airlift/bytecode/TestBytecodeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
*/
package io.airlift.bytecode;

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

import static io.airlift.bytecode.BytecodeUtils.toJavaIdentifierString;
import static org.testng.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public class TestBytecodeUtils
class TestBytecodeUtils
{
@Test
public void testToJavaIdentifierString()
void testToJavaIdentifierString()
{
assertEquals(toJavaIdentifierString("HelloWorld"), "HelloWorld");
assertEquals(toJavaIdentifierString("Hello$World"), "Hello$World");
assertEquals(toJavaIdentifierString("Hello#World"), "Hello_World");
assertEquals(toJavaIdentifierString("A^B^C"), "A_B_C");
assertThat(toJavaIdentifierString("HelloWorld")).isEqualTo("HelloWorld");
assertThat(toJavaIdentifierString("Hello$World")).isEqualTo("Hello$World");
assertThat(toJavaIdentifierString("Hello#World")).isEqualTo("Hello_World");
assertThat(toJavaIdentifierString("A^B^C")).isEqualTo("A_B_C");
}
}
9 changes: 4 additions & 5 deletions src/test/java/io/airlift/bytecode/TestClassGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.airlift.bytecode;

import com.google.common.collect.ImmutableList;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.StringWriter;
import java.lang.reflect.Method;
Expand All @@ -32,12 +32,11 @@
import static io.airlift.bytecode.expression.BytecodeExpressions.add;
import static java.nio.file.Files.createTempDirectory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;

public class TestClassGenerator
class TestClassGenerator
{
@Test
public void testGenerator()
void testGenerator()
throws Exception
{
ClassDefinition classDefinition = new ClassDefinition(
Expand Down Expand Up @@ -72,7 +71,7 @@ public void testGenerator()
.defineClass(classDefinition, Object.class);

Method add = clazz.getMethod("add", int.class, int.class);
assertEquals(add.invoke(null, 13, 42), 55);
assertThat(add.invoke(null, 13, 42)).isEqualTo(55);

assertThat(writer.toString())
.contains("00002 I I : I I : IADD")
Expand Down
30 changes: 15 additions & 15 deletions src/test/java/io/airlift/bytecode/TestFastMethodHandleProxies.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.airlift.bytecode;

import com.google.common.base.VerifyException;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.lang.invoke.MethodHandle;
Expand All @@ -28,19 +28,19 @@

import static java.lang.invoke.MethodHandles.lookup;
import static java.lang.invoke.MethodType.methodType;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.testng.Assert.assertEquals;

public class TestFastMethodHandleProxies
class TestFastMethodHandleProxies
{
@Test
public void testBasic()
void testBasic()
throws ReflectiveOperationException
{
assertInterface(
LongUnaryOperator.class,
lookup().findStatic(getClass(), "increment", methodType(long.class, long.class)),
addOne -> assertEquals(addOne.applyAsLong(1), 2L));
addOne -> assertThat(addOne.applyAsLong(1)).isEqualTo(2L));
}

private static long increment(long x)
Expand All @@ -49,13 +49,13 @@ private static long increment(long x)
}

@Test
public void testGeneric()
void testGeneric()
throws ReflectiveOperationException
{
assertInterface(
LongFunction.class,
lookup().findStatic(getClass(), "incrementAndPrint", methodType(String.class, long.class)),
print -> assertEquals(print.apply(1), "2"));
print -> assertThat(print.apply(1)).isEqualTo("2"));
}

private static String incrementAndPrint(long x)
Expand All @@ -64,15 +64,15 @@ private static String incrementAndPrint(long x)
}

@Test
public void testObjectAndDefaultMethods()
void testObjectAndDefaultMethods()
throws ReflectiveOperationException
{
assertInterface(
StringLength.class,
lookup().findStatic(getClass(), "stringLength", methodType(int.class, String.class)),
length -> {
assertEquals(length.length("abc"), 3);
assertEquals(length.theAnswer(), 42);
assertThat(length.length("abc")).isEqualTo(3);
assertThat(length.theAnswer()).isEqualTo(42);
});
}

Expand All @@ -95,7 +95,7 @@ default int theAnswer()
}

@Test
public void testUncheckedException()
void testUncheckedException()
throws ReflectiveOperationException
{
assertInterface(
Expand All @@ -111,7 +111,7 @@ private static void throwUncheckedException()
}

@Test
public void testCheckedException()
void testCheckedException()
throws ReflectiveOperationException
{
assertInterface(
Expand All @@ -129,7 +129,7 @@ private static void throwCheckedException()
}

@Test
public void testMutableCallSite()
void testMutableCallSite()
throws ReflectiveOperationException
{
MethodHandle one = lookup().findStatic(getClass(), "one", methodType(int.class));
Expand All @@ -141,9 +141,9 @@ public void testMutableCallSite()
callSite.dynamicInvoker(),
supplier -> {
callSite.setTarget(one);
assertEquals(supplier.getAsInt(), 1);
assertThat(supplier.getAsInt()).isEqualTo(1);
callSite.setTarget(two);
assertEquals(supplier.getAsInt(), 2);
assertThat(supplier.getAsInt()).isEqualTo(2);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
package io.airlift.bytecode;

import com.google.common.collect.ImmutableList;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

import java.io.StringWriter;
import java.lang.reflect.Method;
Expand All @@ -34,12 +34,11 @@
import static java.lang.invoke.MethodHandles.lookup;
import static java.nio.file.Files.createTempDirectory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.assertEquals;

public class TestHiddenClassGenerator
class TestHiddenClassGenerator
{
@Test
public void testGenerator()
void testGenerator()
throws Exception
{
ClassDefinition classDefinition = new ClassDefinition(
Expand Down Expand Up @@ -74,7 +73,7 @@ public void testGenerator()
.defineHiddenClass(classDefinition, Object.class, Optional.of("class data"));

Method add = clazz.getMethod("add", int.class, int.class);
assertEquals(add.invoke(null, 13, 42), 55);
assertThat(add.invoke(null, 13, 42)).isEqualTo(55);

assertThat(writer.toString())
.contains("00002 I I : I I : IADD")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
import static io.airlift.bytecode.BytecodeUtils.uniqueClassName;
import static io.airlift.bytecode.ClassGenerator.classGenerator;
import static io.airlift.bytecode.ParameterizedType.type;
import static org.testng.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;

public final class BytecodeExpressionAssertions
{
public static final AtomicBoolean DUMP_BYTECODE_TREE = new AtomicBoolean();
private static final AtomicBoolean DUMP_BYTECODE_TREE = new AtomicBoolean();

private BytecodeExpressionAssertions() {}

static void assertBytecodeExpressionType(BytecodeExpression expression, ParameterizedType type)
{
assertEquals(expression.getType(), type);
assertThat(expression.getType()).isEqualTo(type);
}

public static void assertBytecodeExpression(BytecodeExpression expression, Object expected, String expectedRendering)
Expand All @@ -53,7 +53,7 @@ public static void assertBytecodeExpression(BytecodeExpression expression, Objec
public static void assertBytecodeExpression(BytecodeExpression expression, Object expected, String expectedRendering, Optional<ClassLoader> parentClassLoader)
throws Exception
{
assertEquals(expression.toString(), expectedRendering);
assertThat(expression.toString()).isEqualTo(expectedRendering);

assertBytecodeNode(expression.ret(), expression.getType(), expected, parentClassLoader);
}
Expand All @@ -79,7 +79,7 @@ public static void assertBytecodeNode(BytecodeNode node, ParameterizedType retur
public static void assertBytecodeNode(BytecodeNode node, ParameterizedType returnType, Object expected, Optional<ClassLoader> parentClassLoader)
throws Exception
{
assertEquals(execute(context -> node, returnType, parentClassLoader), expected);
assertThat(execute(context -> node, returnType, parentClassLoader)).isEqualTo(expected);
}

public static void assertBytecodeNode(Function<Scope, BytecodeNode> nodeGenerator, ParameterizedType returnType, Object expected)
Expand All @@ -91,7 +91,7 @@ public static void assertBytecodeNode(Function<Scope, BytecodeNode> nodeGenerato
public static void assertBytecodeNode(Function<Scope, BytecodeNode> nodeGenerator, ParameterizedType returnType, Object expected, Optional<ClassLoader> parentClassLoader)
throws Exception
{
assertEquals(execute(nodeGenerator, returnType, parentClassLoader), expected);
assertThat(execute(nodeGenerator, returnType, parentClassLoader)).isEqualTo(expected);
}

public static Object execute(Function<Scope, BytecodeNode> nodeGenerator, ParameterizedType returnType, Optional<ClassLoader> parentClassLoader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
package io.airlift.bytecode.expression;

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

import static io.airlift.bytecode.expression.BytecodeExpressionAssertions.assertBytecodeExpression;
import static io.airlift.bytecode.expression.BytecodeExpressions.add;
Expand All @@ -33,10 +33,10 @@
import static io.airlift.bytecode.expression.BytecodeExpressions.shiftRightUnsigned;
import static io.airlift.bytecode.expression.BytecodeExpressions.subtract;

public class TestArithmeticBytecodeExpression
class TestArithmeticBytecodeExpression
{
@Test
public void testAdd()
void testAdd()
throws Exception
{
assertBytecodeExpression(add(constantInt(3), constantInt(7)), 3 + 7, "(3 + 7)");
Expand All @@ -46,7 +46,7 @@ public void testAdd()
}

@Test
public void testSubtract()
void testSubtract()
throws Exception
{
assertBytecodeExpression(subtract(constantInt(3), constantInt(7)), 3 - 7, "(3 - 7)");
Expand All @@ -56,7 +56,7 @@ public void testSubtract()
}

@Test
public void testMultiply()
void testMultiply()
throws Exception
{
assertBytecodeExpression(multiply(constantInt(3), constantInt(7)), 3 * 7, "(3 * 7)");
Expand All @@ -66,7 +66,7 @@ public void testMultiply()
}

@Test
public void testDivide()
void testDivide()
throws Exception
{
assertBytecodeExpression(divide(constantInt(7), constantInt(3)), 7 / 3, "(7 / 3)");
Expand All @@ -76,7 +76,7 @@ public void testDivide()
}

@Test
public void testRemainder()
void testRemainder()
throws Exception
{
assertBytecodeExpression(remainder(constantInt(7), constantInt(3)), 7 % 3, "(7 % 3)");
Expand All @@ -86,55 +86,56 @@ public void testRemainder()
}

@Test
public void testShiftLeft()
void testShiftLeft()
throws Exception
{
assertBytecodeExpression(shiftLeft(constantInt(7), constantInt(3)), 7 << 3, "(7 << 3)");
assertBytecodeExpression(shiftLeft(constantLong(7), constantInt(3)), 7L << 3, "(7L << 3)");
}

@Test
public void testShiftRight()
void testShiftRight()
throws Exception
{
assertBytecodeExpression(shiftRight(constantInt(-7), constantInt(3)), -7 >> 3, "(-7 >> 3)");
assertBytecodeExpression(shiftRight(constantLong(-7), constantInt(3)), -7L >> 3, "(-7L >> 3)");
}

@Test
public void testShiftRightUnsigned()
void testShiftRightUnsigned()
throws Exception
{
assertBytecodeExpression(shiftRightUnsigned(constantInt(-7), constantInt(3)), -7 >>> 3, "(-7 >>> 3)");
assertBytecodeExpression(shiftRightUnsigned(constantLong(-7), constantInt(3)), -7L >>> 3, "(-7L >>> 3)");
}

@Test
public void testBitwiseAnd()
void testBitwiseAnd()
throws Exception
{
assertBytecodeExpression(bitwiseAnd(constantInt(101), constantInt(37)), 101 & 37, "(101 & 37)");
assertBytecodeExpression(bitwiseAnd(constantLong(101), constantLong(37)), 101L & 37L, "(101L & 37L)");
}

@Test
public void testBitwiseOr()
void testBitwiseOr()
throws Exception
{
assertBytecodeExpression(bitwiseOr(constantInt(101), constantInt(37)), 101 | 37, "(101 | 37)");
assertBytecodeExpression(bitwiseOr(constantLong(101), constantLong(37)), 101L | 37L, "(101L | 37L)");
}

@Test
public void testBitwiseXor()
void testBitwiseXor()
throws Exception
{
assertBytecodeExpression(bitwiseXor(constantInt(101), constantInt(37)), 101 ^ 37, "(101 ^ 37)");
assertBytecodeExpression(bitwiseXor(constantLong(101), constantLong(37)), 101L ^ 37L, "(101L ^ 37L)");
}

@SuppressWarnings("UnnecessaryUnaryMinus")
@Test
public void testNegate()
void testNegate()
throws Exception
{
assertBytecodeExpression(negate(constantInt(3)), -3, "-(3)");
Expand Down
Loading

0 comments on commit 5f9e2af

Please sign in to comment.