53 assertThat(hasPrivateConstructor(GrammarFunctions.Standard.class)).isTrue();
54 }
55
56 private static final boolean hasPrivateConstructor(Class cls) throws Exception {57 var constructor = cls.getDeclaredConstructor();58 var result = !constructor.isAccessible();59 constructor.setAccessible(true);60 constructor.newInstance();61 return result;62 }63
64}
164 return checkMessage;
165 }
166
167 private static final CheckMessage mockCheckMessage(Integer line, String message) {168 return mockCheckMessage(line, message, null);169 }170
171}
155 .noMore();
156 }
157
158 private static final CheckMessage mockCheckMessage(Integer line, String message, Double cost) {159 CheckMessage checkMessage = mock(CheckMessage.class);160 when(checkMessage.getLine()).thenReturn(line);161 when(checkMessage.getDefaultMessage()).thenReturn(message);162 when(checkMessage.getText(Mockito.any(Locale.class))).thenReturn(message);163 when(checkMessage.getCost()).thenReturn(cost);164 return checkMessage;165 }166
167 private static final CheckMessage mockCheckMessage(Integer line, String message) {
168 return mockCheckMessage(line, message, null);
Private final methods that do not access instance fields should be declared static.
Since the method is private and final, it can't possibly be overridden. Therefore, the only possible definition of the method that exists doesn't access any instance fields. So we can safely declare it as static.
public class Klass {
private final int aField = 10;
private final void method() {
// ...statements that do not access `aField`
}
}
Consider declaring the method static.
public class Klass {
private final int aField = 10;
private static final void method() {
// ...statements that do not access `aField`
}
}