Ray Milkey

Refactor criterion codec

The previous implementation was a huge switch statement. These
changes attempt to use polymorphism to avoid all of the branching
inherent in a switch.

Change-Id: If997f028346de02b883356bcde07f62674e319be
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
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 + */
16 +package org.onosproject.codec.impl;
17 +
18 +import java.util.EnumMap;
19 +
20 +import org.junit.Test;
21 +import org.onosproject.net.flow.criteria.Criterion;
22 +
23 +import static org.onlab.junit.TestUtils.getField;
24 +import static org.hamcrest.MatcherAssert.assertThat;
25 +import static org.hamcrest.Matchers.*;
26 +
27 +/**
28 + * Unit tests for criterion codec.
29 + */
30 +public class CriterionCodecTest {
31 +
32 + /**
33 + * Checks that all criterion types are covered by the codec.
34 + */
35 + @Test
36 + public void checkCriterionTypes() throws Exception {
37 + CriterionCodec codec = new CriterionCodec();
38 + EnumMap<Criterion.Type, Object> formatMap = getField(codec, "formatMap");
39 + assertThat(formatMap, notNullValue());
40 +
41 + for (Criterion.Type type : Criterion.Type.values()) {
42 + assertThat("Entry not found for " + type.toString(),
43 + formatMap.get(type), notNullValue());
44 + }
45 + }
46 +}