From bcd496a1f49f9bc609bf3dd17eda6639d482ce5f Mon Sep 17 00:00:00 2001 From: SirWayne Date: Thu, 16 Jun 2016 15:33:00 +0200 Subject: [PATCH] Add Base Entity Matcher Signed-off-by: SirWayne --- .../test/matcher/BaseEntityMatcher.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/matcher/BaseEntityMatcher.java diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/matcher/BaseEntityMatcher.java b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/matcher/BaseEntityMatcher.java new file mode 100644 index 000000000..cb3f5476f --- /dev/null +++ b/hawkbit-repository/hawkbit-repository-test/src/main/java/org/eclipse/hawkbit/repository/test/matcher/BaseEntityMatcher.java @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2015 Bosch Software Innovations GmbH and others. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + */ +package org.eclipse.hawkbit.repository.test.matcher; + +import org.eclipse.hawkbit.repository.model.BaseEntity; +import org.hamcrest.Factory; +import org.hamcrest.FeatureMatcher; +import org.hamcrest.Matcher; +import org.hamcrest.Matchers; + +/** + * Matcher for {@link BaseEntity}. + */ +public class BaseEntityMatcher { + + private BaseEntityMatcher() { + } + + @Factory + public static Matcher hasId(final Long id) { + return new HasIdMatcher(Matchers.equalTo(id)); + } + + private static class HasIdMatcher extends FeatureMatcher { + + public HasIdMatcher(final Matcher subMatcher) { + super(subMatcher, "getId()", "id"); + } + + @Override + protected Long featureValueOf(final BaseEntity baseEntity) { + return baseEntity.getId(); + } + } + +}