public static Matcher<Component> hasBorderTitle(final Matcher<String> m) { return new FeatureMatcher<Component, String>(m, "title", "title") { @Override protected String featureValueOf(Component actual) { if (actual instanceof JPanel) { Border border = ((JPanel) actual).getBorder(); if (border == null) { return null; } if (border instanceof TitledBorder) { return ((TitledBorder) border).getTitle(); } return "BORDER CLASS " + border.getClass() + " DOES NOT WORK HERE"; // fixme: stupid! } return "CLASS " + actual.getClass() + " DOES NOT WORK HERE"; // fixme: stupid! } }; }
public static Matcher<Component> hasValue(final Matcher<String> m) { return new FeatureMatcher<Component, String>(m, "value", "value") { @Override protected String featureValueOf(Component actual) { if (actual instanceof JTextField) { return ((JTextField) actual).getText(); } if (actual instanceof JLabel) { return ((JLabel) actual).getText(); } return "CLASS " + actual.getClass() + " DOES NOT WORK HERE"; // fixme: stupid! } }; }
/** * Returns a matcher whether the item has the specified contents or not. * @param value the expected contents * @return the matcher */ public static Matcher<ResourceItem> hasContents(String value) { return new FeatureMatcher<ResourceItem, String>(is(value), "has contents", "hasContents") { @Override protected String featureValueOf(ResourceItem actual) { String contents = contents(actual); try { String provider = new String(dump(actual), ENCODING); assertThat(provider, is(contents)); } catch (IOException e) { throw new AssertionError(e); } return contents; } }; }
@Test public void apiWithAcceptAsYaml() throws Exception { final MediaType yaml = MediaType.parseMediaType("application/yaml"); final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); final JsonNode expected = mapper.readTree(yamlResource.getInputStream()); mvc.perform(request(HttpMethod.GET, API_PATH) .accept(yaml)) .andExpect(content().contentType(yaml)) .andExpect(content().string(new FeatureMatcher<String, JsonNode>(equalTo(expected), "yaml", "yaml") { @Override protected JsonNode featureValueOf(String actual) { try { return mapper.readTree(actual); } catch (IOException e) { throw new AssertionError(e); } } })); }
public static Matcher<Diagnostic<? extends JavaFileObject>> hasMessage( Matcher<String> messageMatcher ) { return new FeatureMatcher<Diagnostic<? extends JavaFileObject>, String>(messageMatcher, "message", "message") { @Override protected String featureValueOf(Diagnostic<? extends JavaFileObject> actual) { return actual.getMessage(Locale.ENGLISH); } }; }
public static <Q extends TypeName> Matcher<ParameterSpec> type(Matcher<Q> match) { return new FeatureMatcher<ParameterSpec, Q>(match, "type name", "type name") { @Override protected Q featureValueOf(ParameterSpec actual) { return (Q) actual.type; } }; }
public static Matcher<TypeSpec> name(Matcher<String> match) { return new FeatureMatcher<TypeSpec, String>(match, "type name", "type name") { @Override protected String featureValueOf(TypeSpec actual) { return actual.name; } }; }
public static Matcher<TypeSpec> superInterfaces(Matcher<Iterable<? extends TypeName>> memberMatcher) { return new FeatureMatcher<TypeSpec, Iterable<? extends TypeName>>(memberMatcher, "super interfaces", "super interfaces") { @Override protected Iterable<? extends TypeName> featureValueOf(TypeSpec actual) { return actual.superinterfaces; } }; }
public static Matcher<TypeSpec> methods(Matcher<Iterable<? extends MethodSpec>> memberMatcher) { return new FeatureMatcher<TypeSpec, Iterable<? extends MethodSpec>>(memberMatcher, "method", "method") { @Override protected Iterable<? extends MethodSpec> featureValueOf(TypeSpec actual) { return actual.methodSpecs; } }; }
public static Matcher<TypeSpec> fields(Matcher<Iterable<? extends FieldSpec>> memberMatcher) { return new FeatureMatcher<TypeSpec, Iterable<? extends FieldSpec>>(memberMatcher, "field", "field") { @Override protected Iterable<? extends FieldSpec> featureValueOf(TypeSpec actual) { return actual.fieldSpecs; } }; }
public static Matcher<TypeSpec> innerTypes(Matcher<Iterable<? extends TypeSpec>> typeMatcher) { return new FeatureMatcher<TypeSpec, Iterable<? extends TypeSpec>>(typeMatcher, "inner type", "inner type") { @Override protected Iterable<? extends TypeSpec> featureValueOf(TypeSpec actual) { return actual.typeSpecs; } }; }
public static Matcher<Map.Entry<?, ?>> key(Matcher<?> matcher) { return new FeatureMatcher<Map.Entry<?, ?>, Object>((Matcher<? super Object>) matcher, "key", "key") { @Override protected Object featureValueOf(Map.Entry<?, ?> actual) { return actual.getKey(); } }; }
public static Matcher<FieldSpec> fieldName(Matcher<String> match) { return new FeatureMatcher<FieldSpec, String>(match, "field name", "field name") { @Override protected String featureValueOf(FieldSpec actual) { return actual.name; } }; }
public static Matcher<FieldSpec> initializer(Matcher<String> match) { return new FeatureMatcher<FieldSpec, String>(match, "field initializer", "field initializer") { @Override protected String featureValueOf(FieldSpec actual) { return actual.initializer.toString(); } }; }
public static <T extends TypeName> Matcher<FieldSpec> fieldType(Matcher<T> match) { return new FeatureMatcher<FieldSpec, T>(match, "type name", "type name") { @Override protected T featureValueOf(FieldSpec actual) { return (T) actual.type; } }; }
public static Matcher<MethodSpec> methodName(Matcher<String> match) { return new FeatureMatcher<MethodSpec, String>(match, "method name", "method name") { @Override protected String featureValueOf(MethodSpec actual) { return actual.name; } }; }
public static<K extends TypeName> Matcher<MethodSpec> returnType(Matcher<K> match) { return new FeatureMatcher<MethodSpec, K>(match, "return type", "return type") { @Override protected K featureValueOf(MethodSpec actual) { return (K)actual.returnType; } }; }
public static Matcher<MethodSpec> codeContent(Matcher<String> match) { return new FeatureMatcher<MethodSpec, String>(match, "method content", "method content") { @Override protected String featureValueOf(MethodSpec actual) { return actual.code.toString(); } }; }
public static Matcher<MethodSpec> parameters(Matcher<Iterable<? extends ParameterSpec>> memberMatcher) { return new FeatureMatcher<MethodSpec, Iterable<? extends ParameterSpec>>(memberMatcher, "parameter", "parameter") { @Override protected Iterable<? extends ParameterSpec> featureValueOf(MethodSpec actual) { return actual.parameters; } }; }
Matcher<Token> tokenId(Matcher<HotaruTokenId> matcher) { return new FeatureMatcher<Token, HotaruTokenId>(matcher, "tokenId", "tokenId") { @Override protected HotaruTokenId featureValueOf(Token actual) { return actual.getType(); } }; }
static org.hamcrest.Matcher<CompletionProposal> proposalThat(org.hamcrest.Matcher<String> matcher) { return new FeatureMatcher<CompletionProposal, String>(matcher, "a proposal whose text", "text") { @Override protected String featureValueOf(CompletionProposal actual) { return actual.getText(); } }; }
private static Matcher<MobileAnnouncementDTO> hasAnnouncementBody(Matcher<String> childMatcher) { return new FeatureMatcher<MobileAnnouncementDTO, String>(childMatcher, "body", "body") { @Override protected String featureValueOf(MobileAnnouncementDTO actual) { return actual.getBody(); } }; }
private static Matcher<MobileAnnouncementDTO> hasAnnouncementSubject(Matcher<String> childMatcher) { return new FeatureMatcher<MobileAnnouncementDTO, String>(childMatcher, "subject", "subject") { @Override protected String featureValueOf(MobileAnnouncementDTO actual) { return actual.getSubject(); } }; }
private static Matcher<MobileAnnouncementDTO> hasAnnouncementId(Matcher<Long> childMatcher) { return new FeatureMatcher<MobileAnnouncementDTO, Long>(childMatcher, "id", "id") { @Override protected Long featureValueOf(MobileAnnouncementDTO actual) { return actual.getId(); } }; }
public static FeatureMatcher<ListAnnouncementDTO, String> hasBody(final String expected) { return new FeatureMatcher<ListAnnouncementDTO, String>(equalTo(expected), "body", "body") { @Override protected String featureValueOf(final ListAnnouncementDTO announcement) { return announcement.getBody(); } }; }
public static FeatureMatcher<ListAnnouncementDTO, String> hasSubject(final String expected) { return new FeatureMatcher<ListAnnouncementDTO, String>(equalTo(expected), "subject", "subject") { @Override protected String featureValueOf(final ListAnnouncementDTO announcement) { return announcement.getSubject(); } }; }
public static FeatureMatcher<ListAnnouncementDTO, AnnouncementSenderType> hasSenderType(final AnnouncementSenderType expected) { return new FeatureMatcher<ListAnnouncementDTO, AnnouncementSenderType>(equalTo(expected), "senderType", "senderType") { @Override protected AnnouncementSenderType featureValueOf(final ListAnnouncementDTO announcement) { return announcement.getSenderType(); } }; }
public static FeatureMatcher<ListAnnouncementDTO, Map<String, String>> hasFromOrganisation(final Organisation expected) { return new FeatureMatcher<ListAnnouncementDTO, Map<String, String>>(equalTo(expected.getNameLocalisation().asMap()), "fromOrganisation", "fromOrganisation") { @Override protected Map<String, String> featureValueOf(final ListAnnouncementDTO announcement) { return announcement.getFromOrganisation().getName(); } }; }
public static Matcher<Occupation> hasOccupationType(final Matcher<OccupationType> childMatcher) { return new FeatureMatcher<Occupation, OccupationType>(childMatcher, "occupationType", "occupationType") { @Override protected OccupationType featureValueOf(Occupation actual) { return actual.getOccupationType(); } }; }
public static Matcher<Occupation> hasPersonId(final Matcher<Long> childMatcher) { return new FeatureMatcher<Occupation, Long>(childMatcher, "personId", "personId") { @Override protected Long featureValueOf(Occupation actual) { return F.getId(actual.getPerson()); } }; }
public static Matcher<Occupation> hasCallOrder(final Matcher<Integer> childMatcher) { return new FeatureMatcher<Occupation, Integer>(childMatcher, "callOrder", "callOrder") { @Override protected Integer featureValueOf(Occupation actual) { return actual.getCallOrder(); } }; }
public static <T extends HasID<Long>> Matcher<T> hasId(Matcher<Long> childMatcher) { return new FeatureMatcher<T, Long>(childMatcher, "id", "id") { @Override protected Long featureValueOf(T actual) { return actual.getId(); } }; }
public static Matcher<StorableFence> isNotAnd() { return new FeatureMatcher<StorableFence, Boolean>(equalTo(true), "andFences empty", "andFences empty") { @Override protected Boolean featureValueOf(StorableFence fence) { return fence.getAndFences().isEmpty(); } }; }
public static Matcher<StorableFence> isNotOr() { return new FeatureMatcher<StorableFence, Boolean>(equalTo(true), "orFences empty", "orFences empty") { @Override protected Boolean featureValueOf(StorableFence fence) { return fence.getOrFences().isEmpty(); } }; }
public static Matcher<StorableFence> isNotNot() { return new FeatureMatcher<StorableFence, Boolean>(equalTo(true), "notFence is null", "notFence is null") { @Override protected Boolean featureValueOf(StorableFence fence) { return fence.getNotFence() == null; } }; }
private static DeliveryOptions withTimeout(final Long expectedTimeout) { return MockitoHamcrest.argThat(new FeatureMatcher<DeliveryOptions, Long>(IsEqual.equalTo(expectedTimeout), "timeout", "timeout") { @Override protected Long featureValueOf(DeliveryOptions deliveryOptions) { return deliveryOptions.getSendTimeout(); } }); }
private <T> FeatureMatcher<RestifyEndpointResponseException, T> method(Function<RestifyEndpointResponseException, T> function, Matcher<T> matcher) { return new FeatureMatcher<RestifyEndpointResponseException, T>(matcher, "method", "value") { @Override protected T featureValueOf(RestifyEndpointResponseException actual) { return function.apply(actual); } }; }
public static Matcher<RecordedRequest> withPath(String path) { return new FeatureMatcher<RecordedRequest, String>(equalTo(path), "request path", "path") { @Override protected String featureValueOf(RecordedRequest recordedRequest) { return recordedRequest.getPath(); } }; }
public static Matcher<File> fileWithConents(Matcher<String> contentsMatcher) { return new FeatureMatcher<File, String>(contentsMatcher, "file contents", "file contents") { @Override protected String featureValueOf(File file) { try { return FileUtils.readFileToString(file, StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } } }; }