Skip to content

Commit

Permalink
Replaced deprecated mockito method calls, removed unused import state…
Browse files Browse the repository at this point in the history
…ments, minor other improvements
  • Loading branch information
unkish authored and joelittlejohn committed Dec 17, 2021
1 parent c487f1d commit df9513f
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.io.IOException;
Expand All @@ -41,7 +40,7 @@
public class SchemaMapperTest {

@Test
public void generateReadsSchemaAsObject() throws IOException {
public void generateReadsSchemaAsObject() {

final SchemaRule mockSchemaRule = mock(SchemaRule.class);

Expand All @@ -64,7 +63,7 @@ public void generateReadsSchemaAsObject() throws IOException {
}

@Test
public void generateCreatesSchemaFromExampleJsonWhenInJsonMode() throws IOException {
public void generateCreatesSchemaFromExampleJsonWhenInJsonMode() {

URL schemaContent = this.getClass().getResource("/schema/address.json");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,28 @@
import static org.mockito.Mockito.*;

import java.io.File;
import java.io.IOException;
import java.util.Comparator;

import org.junit.Test;

public class SourceSortOrderTest {
@Test
public void testTwoFilesAreCompared_FILES_FIRST() throws IOException {
public void testTwoFilesAreCompared_FILES_FIRST() {
testTwoFilesAreCompared(SourceSortOrder.FILES_FIRST.getComparator());
}

@Test
public void twoDirectoriesAreCompared_FILES_FIRST() throws IOException {
public void twoDirectoriesAreCompared_FILES_FIRST() {
testTwoDirectoriesAreCompared(SourceSortOrder.FILES_FIRST.getComparator());
}

@Test
public void testTwoFilesAreCompared_SUBDIRS_FIRST() throws IOException {
public void testTwoFilesAreCompared_SUBDIRS_FIRST() {
testTwoFilesAreCompared(SourceSortOrder.SUBDIRS_FIRST.getComparator());
}

@Test
public void twoDirectoriesAreCompared_SUBDIRS_FIRST() throws IOException {
public void twoDirectoriesAreCompared_SUBDIRS_FIRST() {
testTwoDirectoriesAreCompared(SourceSortOrder.SUBDIRS_FIRST.getComparator());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static java.util.Arrays.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -56,7 +55,7 @@ public class DigitsRuleTest {

private final boolean isApplicable;
private DigitsRule rule;
private Class<?> fieldClass;
private final Class<?> fieldClass;
private final boolean useJakartaValidation;
private final Class<? extends Annotation> digitsClass;
private final Class<? extends Annotation> sizeClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import org.jsonschema2pojo.Annotator;
Expand All @@ -27,7 +26,7 @@
import org.jsonschema2pojo.util.NameHelper;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

Expand All @@ -41,14 +40,14 @@

public class EnumRuleTest {

private Schema schema = mock(Schema.class);
private NameHelper nameHelper = mock(NameHelper.class);
private Annotator annotator = mock(Annotator.class);
private RuleFactory ruleFactory = mock(RuleFactory.class);
private TypeRule typeRule = mock(TypeRule.class);
private RuleLogger logger = mock(RuleLogger.class);
private final Schema schema = mock(Schema.class);
private final NameHelper nameHelper = mock(NameHelper.class);
private final Annotator annotator = mock(Annotator.class);
private final RuleFactory ruleFactory = mock(RuleFactory.class);
private final TypeRule typeRule = mock(TypeRule.class);
private final RuleLogger logger = mock(RuleLogger.class);

private EnumRule rule = new EnumRule(ruleFactory);
private final EnumRule rule = new EnumRule(ruleFactory);

@Before
public void wireUpConfig() {
Expand All @@ -62,7 +61,7 @@ public void wireUpConfig() {
public void applyGeneratesUniqueEnumNamesForMultipleEnumNodesWithSameName() {

Answer<String> firstArgAnswer = new FirstArgAnswer<>();
when(nameHelper.getClassName(anyString(), Matchers.any(JsonNode.class))).thenAnswer(firstArgAnswer);
when(nameHelper.getClassName(anyString(), ArgumentMatchers.any(JsonNode.class))).thenAnswer(firstArgAnswer);
when(nameHelper.replaceIllegalCharacters(anyString())).thenAnswer(firstArgAnswer);
when(nameHelper.normalizeName(anyString())).thenAnswer(firstArgAnswer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static java.util.Arrays.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -55,7 +54,7 @@ public class MinItemsMaxItemsRuleTest {

private final boolean isApplicable;
private MinItemsMaxItemsRule rule;
private Class<?> fieldClass;
private final Class<?> fieldClass;
private final boolean useJakartaValidation;
private final Class<? extends Annotation> sizeClass;
@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static java.util.Arrays.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -55,7 +54,7 @@ public class MinLengthMaxLengthRuleTest {

private final boolean isApplicable;
private MinLengthMaxLengthRule rule;
private Class<?> fieldClass;
private final Class<?> fieldClass;
private final boolean useJakartaValidation;
private final Class<? extends Annotation> sizeClass;
@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static java.util.Arrays.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -57,7 +56,7 @@ public class MinimumMaximumRuleTest {

private final boolean isApplicable;
private MinimumMaximumRule rule;
private Class<?> fieldClass;
private final Class<?> fieldClass;
private final boolean useJakartaValidation;
private final Class<? extends Annotation> decimalMaxClass;
private final Class<? extends Annotation> decimalMinClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static java.util.Arrays.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -54,7 +53,7 @@ public class PatternRuleTest {

private final boolean isApplicable;
private PatternRule rule;
private Class<?> fieldClass;
private final Class<?> fieldClass;
private final boolean useJakartaValidation;
private final Class<? extends Annotation> patternClass;
@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import java.net.URI;
Expand All @@ -44,8 +42,8 @@ public class SchemaRuleTest {
private static final String NODE_NAME = "nodeName";
private static final String TARGET_CLASS_NAME = SchemaRuleTest.class.getName() + ".DummyClass";

private RuleFactory mockRuleFactory = mock(RuleFactory.class);
private SchemaRule rule = new SchemaRule(mockRuleFactory);
private final RuleFactory mockRuleFactory = mock(RuleFactory.class);
private final SchemaRule rule = new SchemaRule(mockRuleFactory);

@Test
public void refsToOtherSchemasAreLoaded() throws URISyntaxException, JClassAlreadyExistsException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,12 @@

import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import java.math.BigDecimal;
import java.math.BigInteger;

import org.jsonschema2pojo.GenerationConfig;
import org.jsonschema2pojo.Schema;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
Expand All @@ -42,10 +39,10 @@

public class TypeRuleTest {

private GenerationConfig config = mock(GenerationConfig.class);
private RuleFactory ruleFactory = mock(RuleFactory.class);
private final GenerationConfig config = mock(GenerationConfig.class);
private final RuleFactory ruleFactory = mock(RuleFactory.class);

private TypeRule rule = new TypeRule(ruleFactory);
private final TypeRule rule = new TypeRule(ruleFactory);

@Before
public void wireUpConfig() {
Expand Down Expand Up @@ -78,7 +75,7 @@ public void applyGeneratesDate() {

JType mockDateType = mock(JType.class);
FormatRule mockFormatRule = mock(FormatRule.class);
when(mockFormatRule.apply(eq("fooBar"), eq(formatNode), any(), Mockito.isA(JType.class), isNull(Schema.class))).thenReturn(mockDateType);
when(mockFormatRule.apply(eq("fooBar"), eq(formatNode), any(), Mockito.isA(JType.class), isNull())).thenReturn(mockDateType);
when(ruleFactory.getFormatRule()).thenReturn(mockFormatRule);

JType result = rule.apply("fooBar", objectNode, null, jpackage, null);
Expand Down Expand Up @@ -563,7 +560,7 @@ public void applyGeneratesArray() {

JType result = rule.apply("fooBar", objectNode, null, jpackage, null);

assertThat(result, is((JType) mockArrayType));
assertThat(result, is(mockArrayType));
}

@Test
Expand All @@ -581,7 +578,7 @@ public void applyGeneratesCustomObject() {

JType result = rule.apply("fooBar", objectNode, null, jpackage, null);

assertThat(result, is((JType) mockObjectType));
assertThat(result, is(mockObjectType));
}

@Test
Expand Down

0 comments on commit df9513f

Please sign in to comment.