Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Evgeny Mandrikov
asm
Commits
897069b6
Commit
897069b6
authored
Apr 03, 2022
by
Eric Bruneton
Browse files
Make sure only one invocation in the assertThrows lambda can throw the...
parent
bb8eb912
Changes
5
Hide whitespace changes
Inline
Side-by-side
asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java
View file @
897069b6
...
...
@@ -557,7 +557,7 @@ class GeneratorAdapterTest {
}
@Test
void
testIfCmp
()
{
void
testIfCmp
()
throws
GeneratorException
{
assertEquals
(
"IF_ICMPEQ L0"
,
new
Generator
().
ifCmp
(
Type
.
INT_TYPE
,
EQ
,
new
Label
()));
assertEquals
(
"IF_ICMPNE L0"
,
new
Generator
().
ifCmp
(
Type
.
INT_TYPE
,
NE
,
new
Label
()));
assertEquals
(
"IF_ICMPGE L0"
,
new
Generator
().
ifCmp
(
Type
.
INT_TYPE
,
GE
,
new
Label
()));
...
...
@@ -578,12 +578,11 @@ class GeneratorAdapterTest {
assertEquals
(
"IF_ACMPEQ L0"
,
new
Generator
().
ifCmp
(
Type
.
getType
(
"[I"
),
EQ
,
new
Label
()));
assertEquals
(
"IF_ACMPNE L0"
,
new
Generator
().
ifCmp
(
Type
.
getType
(
"[I"
),
NE
,
new
Label
()));
assertThrows
(
IllegalArgument
Exception
.
class
,
()
->
new
Generator
().
ifCmp
(
OBJECT_TYPE
,
GE
,
new
Label
()));
Generator
Exception
.
class
,
()
->
new
Generator
().
ifCmp
(
OBJECT_TYPE
,
GE
,
new
Label
()));
assertThrows
(
IllegalArgumentException
.
class
,
()
->
new
Generator
().
ifCmp
(
Type
.
getType
(
"[I"
),
GE
,
new
Label
()));
GeneratorException
.
class
,
()
->
new
Generator
().
ifCmp
(
Type
.
getType
(
"[I"
),
GE
,
new
Label
()));
assertThrows
(
IllegalArgument
Exception
.
class
,
()
->
new
Generator
().
ifCmp
(
Type
.
INT_TYPE
,
0
,
new
Label
()));
Generator
Exception
.
class
,
()
->
new
Generator
().
ifCmp
(
Type
.
INT_TYPE
,
0
,
new
Label
()));
}
@Test
...
...
@@ -592,14 +591,14 @@ class GeneratorAdapterTest {
}
@Test
void
testIfICmp
()
{
void
testIfICmp
()
throws
GeneratorException
{
assertEquals
(
"IF_ICMPEQ L0"
,
new
Generator
().
ifICmp
(
EQ
,
new
Label
()));
assertEquals
(
"IF_ICMPNE L0"
,
new
Generator
().
ifICmp
(
NE
,
new
Label
()));
assertEquals
(
"IF_ICMPGE L0"
,
new
Generator
().
ifICmp
(
GE
,
new
Label
()));
assertEquals
(
"IF_ICMPGT L0"
,
new
Generator
().
ifICmp
(
GT
,
new
Label
()));
assertEquals
(
"IF_ICMPLE L0"
,
new
Generator
().
ifICmp
(
LE
,
new
Label
()));
assertEquals
(
"IF_ICMPLT L0"
,
new
Generator
().
ifICmp
(
LT
,
new
Label
()));
assertThrows
(
IllegalArgument
Exception
.
class
,
()
->
new
Generator
().
ifICmp
(
0
,
new
Label
()));
assertThrows
(
Generator
Exception
.
class
,
()
->
new
Generator
().
ifICmp
(
0
,
new
Label
()));
}
@Test
...
...
@@ -633,7 +632,7 @@ class GeneratorAdapterTest {
}
@Test
void
testTableSwitch
()
{
void
testTableSwitch
()
throws
GeneratorException
{
assertEquals
(
"L0 ICONST_M1 L1"
,
new
Generator
().
tableSwitch
(
new
int
[
0
]));
assertEquals
(
"TABLESWITCH\n"
...
...
@@ -662,8 +661,7 @@ class GeneratorAdapterTest {
+
" 4: L2\n"
+
" default: L1 L0 ICONST_0 L2 ICONST_4 L1 ICONST_M1 L3"
,
new
Generator
().
tableSwitch
(
new
int
[]
{
0
,
4
},
true
));
assertThrows
(
IllegalArgumentException
.
class
,
()
->
new
Generator
().
tableSwitch
(
new
int
[]
{
1
,
0
}));
assertThrows
(
GeneratorException
.
class
,
()
->
new
Generator
().
tableSwitch
(
new
int
[]
{
1
,
0
}));
}
@Test
...
...
@@ -835,6 +833,15 @@ class GeneratorAdapterTest {
.
catchException
(
new
Label
(),
new
Label
(),
Type
.
getObjectType
(
"pkg/Exception"
)));
}
private
static
class
GeneratorException
extends
Exception
{
private
static
final
long
serialVersionUID
=
-
7167830120642305483L
;
public
GeneratorException
(
final
Throwable
cause
)
{
super
(
cause
);
}
}
private
static
class
Generator
implements
TableSwitchGenerator
{
private
final
Textifier
textifier
;
...
...
@@ -1057,13 +1064,22 @@ class GeneratorAdapterTest {
return
toString
();
}
public
String
ifCmp
(
final
Type
type
,
final
int
mode
,
final
Label
label
)
{
generatorAdapter
.
ifCmp
(
type
,
mode
,
label
);
public
String
ifCmp
(
final
Type
type
,
final
int
mode
,
final
Label
label
)
throws
GeneratorException
{
try
{
generatorAdapter
.
ifCmp
(
type
,
mode
,
label
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
GeneratorException
(
e
);
}
return
toString
();
}
public
String
ifICmp
(
final
int
mode
,
final
Label
label
)
{
generatorAdapter
.
ifICmp
(
mode
,
label
);
public
String
ifICmp
(
final
int
mode
,
final
Label
label
)
throws
GeneratorException
{
try
{
generatorAdapter
.
ifICmp
(
mode
,
label
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
GeneratorException
(
e
);
}
return
toString
();
}
...
...
@@ -1092,13 +1108,21 @@ class GeneratorAdapterTest {
return
toString
();
}
public
String
tableSwitch
(
final
int
[]
keys
)
{
generatorAdapter
.
tableSwitch
(
keys
,
this
);
public
String
tableSwitch
(
final
int
[]
keys
)
throws
GeneratorException
{
try
{
generatorAdapter
.
tableSwitch
(
keys
,
this
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
GeneratorException
(
e
);
}
return
toString
();
}
public
String
tableSwitch
(
final
int
[]
keys
,
final
boolean
useTable
)
{
generatorAdapter
.
tableSwitch
(
keys
,
this
,
useTable
);
public
String
tableSwitch
(
final
int
[]
keys
,
final
boolean
useTable
)
throws
GeneratorException
{
try
{
generatorAdapter
.
tableSwitch
(
keys
,
this
,
useTable
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
GeneratorException
(
e
);
}
return
toString
();
}
...
...
asm-commons/src/test/java/org/objectweb/asm/commons/InstructionAdapterTest.java
View file @
897069b6
...
...
@@ -62,8 +62,10 @@ class InstructionAdapterTest extends AsmTest {
@Test
void
testConstructor
()
{
assertDoesNotThrow
(()
->
new
InstructionAdapter
(
new
MethodNode
()));
assertThrows
(
IllegalStateException
.
class
,
()
->
new
InstructionAdapter
(
new
MethodNode
())
{});
MethodNode
methodNode
=
new
MethodNode
();
assertDoesNotThrow
(()
->
new
InstructionAdapter
(
methodNode
));
assertThrows
(
IllegalStateException
.
class
,
()
->
new
InstructionAdapter
(
methodNode
)
{});
}
@Test
...
...
asm-commons/src/test/java/org/objectweb/asm/commons/JsrInlinerAdapterTest.java
View file @
897069b6
...
...
@@ -1509,12 +1509,11 @@ class JsrInlinerAdapterTest extends AsmTest {
classReader
.
accept
(
new
JsrInlinerClassAdapter
(
apiParameter
.
value
(),
classWriter
),
0
);
ClassFile
classFile
=
new
ClassFile
(
classWriter
.
toByteArray
());
if
(
classParameter
.
isNotCompatibleWithCurrentJdk
())
{
assertThrows
(
UnsupportedClassVersionError
.
class
,
()
->
new
ClassFile
(
classWriter
.
toByteArray
()).
newInstance
());
assertThrows
(
UnsupportedClassVersionError
.
class
,
()
->
classFile
.
newInstance
());
}
else
{
assertDoesNotThrow
(()
->
new
C
lassFile
(
classWriter
.
toByteArray
())
.
newInstance
());
assertDoesNotThrow
(()
->
c
lassFile
.
newInstance
());
}
}
...
...
asm-commons/src/test/java/org/objectweb/asm/commons/LocalVariablesSorterTest.java
View file @
897069b6
...
...
@@ -59,10 +59,12 @@ class LocalVariablesSorterTest extends AsmTest {
@Test
void
testConstructor
()
{
assertDoesNotThrow
(()
->
new
LocalVariablesSorter
(
Opcodes
.
ACC_PUBLIC
,
"()V"
,
new
MethodNode
()));
MethodNode
methodNode
=
new
MethodNode
();
assertDoesNotThrow
(()
->
new
LocalVariablesSorter
(
Opcodes
.
ACC_PUBLIC
,
"()V"
,
methodNode
));
assertThrows
(
IllegalStateException
.
class
,
()
->
new
LocalVariablesSorter
(
Opcodes
.
ACC_PUBLIC
,
"()V"
,
new
M
ethodNode
()
)
{});
()
->
new
LocalVariablesSorter
(
Opcodes
.
ACC_PUBLIC
,
"()V"
,
m
ethodNode
)
{});
}
@Test
...
...
asm-commons/src/test/java/org/objectweb/asm/commons/TryCatchBlockSorterTest.java
View file @
897069b6
...
...
@@ -84,12 +84,11 @@ class TryCatchBlockSorterTest extends AsmTest {
classReader
.
accept
(
classVisitor
,
0
);
ClassFile
classFile
=
new
ClassFile
(
classWriter
.
toByteArray
());
if
(
classParameter
.
isNotCompatibleWithCurrentJdk
())
{
assertThrows
(
UnsupportedClassVersionError
.
class
,
()
->
new
ClassFile
(
classWriter
.
toByteArray
()).
newInstance
());
assertThrows
(
UnsupportedClassVersionError
.
class
,
()
->
classFile
.
newInstance
());
}
else
{
assertDoesNotThrow
(()
->
new
C
lassFile
(
classWriter
.
toByteArray
())
.
newInstance
());
assertDoesNotThrow
(()
->
c
lassFile
.
newInstance
());
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment