If you really want to do that in one line, you could extend the JButton class and add the listener in a instance initializer:
panel.add(new JButton("text") {{ addActionListener(e -> classX.addNewTest()); }} );
I would not recommend doing that: it is very hard to understand, almost code obfuscation, and it is creating a subclass of JButton without really extending its functionality at all. See What is Double Brace initialization.
A better approach could be to write a method to create buttons - I do this for most components:
panel.add(createJButton("test", e -> classX.addNewTest()));
...
private JButton createJButton(String text, ActionListener listener) {
JButton button = new JButton(text);
button.addActionListener(listener);
// more customization if needed
return button;
}