blob: a038830a52ede5527a61e5c07138a849c455293c [file] [log] [blame]
Madan Jampani2b8e1892015-12-04 11:16:47 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Madan Jampani2b8e1892015-12-04 11:16:47 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.persistence;
17
18import java.util.Map;
19
20import org.onosproject.persistence.PersistentMapBuilder;
21import org.onosproject.persistence.PersistentSetBuilder;
22import org.onosproject.store.service.Serializer;
23
24import com.google.common.collect.Maps;
25
26/**
27 * PersistenceService that produces in memory maps for use in unit testing.
28 */
29public class TestPersistenceService extends PersistenceServiceAdapter {
30 @Override
31 public <K, V> PersistentMapBuilder<K, V> persistentMapBuilder() {
32 return new TestPersistentMapBuilder<K, V>();
33 }
34
35 @Override
36 public <E> PersistentSetBuilder<E> persistentSetBuilder() {
37 throw new UnsupportedOperationException();
38 }
39
40 private static class TestPersistentMapBuilder<K, V> implements PersistentMapBuilder<K, V> {
41
42 @Override
43 public PersistentMapBuilder<K, V> withName(String name) {
44 return this;
45 }
46
47 @Override
48 public PersistentMapBuilder<K, V> withSerializer(Serializer serializer) {
49 return this;
50 }
51
52 @Override
53 public Map<K, V> build() {
54 return Maps.newConcurrentMap();
55 }
56 }
57}