Skip to content

Commit f019128

Browse files
committed
yet more test cleanup
1 parent 5fd8744 commit f019128

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed

src/test/java/com/fasterxml/jackson/databind/jsontype/ext/TestPropertyCreatorSubtypesExternalPropertyMissingProperty.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
package com.fasterxml.jackson.databind.jsontype.ext;
22

3-
import com.fasterxml.jackson.annotation.JsonCreator;
4-
import com.fasterxml.jackson.annotation.JsonProperty;
5-
import com.fasterxml.jackson.annotation.JsonSubTypes;
3+
import com.fasterxml.jackson.annotation.*;
64
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
7-
import com.fasterxml.jackson.annotation.JsonTypeInfo;
85
import com.fasterxml.jackson.annotation.JsonTypeInfo.As;
96
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
10-
import com.fasterxml.jackson.databind.BaseMapTest;
11-
import com.fasterxml.jackson.databind.DeserializationFeature;
12-
import com.fasterxml.jackson.databind.JsonMappingException;
13-
import com.fasterxml.jackson.databind.ObjectMapper;
14-
import com.fasterxml.jackson.databind.ObjectReader;
7+
8+
import com.fasterxml.jackson.databind.*;
159
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
1610

17-
import org.junit.Rule;
1811
import org.junit.Test;
19-
import org.junit.rules.ExpectedException;
2012

2113
import static org.junit.Assert.assertEquals;
2214
import static org.junit.Assert.assertNull;

src/test/java/com/fasterxml/jackson/databind/jsontype/ext/TestSubtypesExternalPropertyMissingProperty.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@
66
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
77

88
import com.fasterxml.jackson.databind.*;
9+
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
910

10-
import org.junit.Rule;
1111
import org.junit.Test;
12-
import org.junit.rules.ExpectedException;
13-
14-
import static org.junit.Assert.assertEquals;
15-
import static org.junit.Assert.assertNull;
16-
import static org.junit.Assert.assertSame;
1712

1813
// for [databind#1341]
19-
public class TestSubtypesExternalPropertyMissingProperty
14+
public class TestSubtypesExternalPropertyMissingProperty extends BaseMapTest
2015
{
21-
@Rule
22-
public ExpectedException thrown = ExpectedException.none();
23-
2416
/**
2517
* Base class - external property for Fruit subclasses.
2618
*/
@@ -95,7 +87,7 @@ public Orange(String name, String c) {
9587
}
9688
}
9789

98-
private final ObjectMapper MAPPER = new ObjectMapper();
90+
private final ObjectMapper MAPPER = newJsonMapper();
9991

10092
/*
10193
/**********************************************************
@@ -246,14 +238,20 @@ private void checkAppleBoxNull(String json) throws Exception {
246238
}
247239

248240
private void checkBoxJsonMappingException(String json) throws Exception {
249-
thrown.expect(JsonMappingException.class);
250-
thrown.expectMessage("Missing property 'fruit' for external type id 'type'");
251-
MAPPER.readValue(json, Box.class);
241+
try {
242+
MAPPER.readValue(json, Box.class);
243+
fail("Should not pass");
244+
} catch (MismatchedInputException e) {
245+
BaseMapTest.verifyException(e, "Missing property 'fruit' for external type id 'type'");
246+
}
252247
}
253248

254249
private void checkReqBoxJsonMappingException(String json) throws Exception {
255-
thrown.expect(JsonMappingException.class);
256-
thrown.expectMessage("Missing property 'fruit' for external type id 'type'");
257-
MAPPER.readValue(json, ReqBox.class);
250+
try {
251+
MAPPER.readValue(json, ReqBox.class);
252+
fail("Should not pass");
253+
} catch (MismatchedInputException e) {
254+
BaseMapTest.verifyException(e, "Missing property 'fruit' for external type id 'type'");
255+
}
258256
}
259257
}

src/test/java/com/fasterxml/jackson/failing/InnerClassNonStaticCore384Test.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
import java.util.List;
66
import java.util.Objects;
77

8-
import static org.hamcrest.CoreMatchers.instanceOf;
9-
10-
import static org.junit.Assert.assertThat;
11-
128
import com.fasterxml.jackson.databind.*;
139
import com.fasterxml.jackson.databind.testutil.NoCheckSubTypeValidator;
1410

@@ -190,8 +186,8 @@ public void testHierarchy() throws IOException {
190186

191187
Fleet deserializedFleet = mapper.readValue(serializedFleet, Fleet.class);
192188

193-
assertThat(deserializedFleet.getVehicles().get(0), instanceOf(Car.class));
194-
assertThat(deserializedFleet.getVehicles().get(1), instanceOf(Truck.class));
189+
assertTrue(deserializedFleet.getVehicles().get(0) instanceof Car);
190+
assertTrue(deserializedFleet.getVehicles().get(1) instanceof Truck);
195191

196192
assertEquals(fleet, deserializedFleet);
197193
}

0 commit comments

Comments
 (0)