7f40dc1b37d82c6a3b6e646d493450a7cba1307d
[controller.git] / opendaylight / md-sal / cds-access-client / src / test / java / org / opendaylight / controller / cluster / access / client / ConnectionEntryMatcher.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.access.client;
9
10 import org.hamcrest.BaseMatcher;
11 import org.hamcrest.Description;
12 import org.opendaylight.controller.cluster.access.concepts.Request;
13
14 /**
15  * Matcher checks, whether matched {@link ConnectionEntry} tracks provided {@link Request}.
16  */
17 class ConnectionEntryMatcher extends BaseMatcher<ConnectionEntry> {
18
19     private final Request<?, ?> request;
20
21     /**
22      * Creates a matcher that matches if the examined {@link ConnectionEntry} contains specified request.
23      *
24      * @param request request
25      * @return matcher
26      */
27     public static ConnectionEntryMatcher entryWithRequest(final Request<?, ?> request) {
28         return new ConnectionEntryMatcher(request);
29     }
30
31     private ConnectionEntryMatcher(final Request<?, ?> request) {
32         this.request = request;
33     }
34
35     @Override
36     public boolean matches(final Object item) {
37         if (!(item instanceof ConnectionEntry)) {
38             return false;
39         }
40         final ConnectionEntry entry = (ConnectionEntry) item;
41         return this.request.equals(entry.getRequest());
42     }
43
44     @Override
45     public void describeMismatch(final Object item, final Description description) {
46         final ConnectionEntry entry = (ConnectionEntry) item;
47         super.describeMismatch(entry.getRequest(), description);
48     }
49
50     @Override
51     public void describeTo(final Description description) {
52         description.appendValue(request);
53     }
54 }