Gridarta Editor
FilterConfigEncoderTest.java
Go to the documentation of this file.
1 package net.sf.gridarta.model.filter;
2 
3 import java.util.Arrays;
4 import java.util.Collections;
7 import org.jetbrains.annotations.NotNull;
8 import org.junit.Assert;
9 import org.junit.Test;
10 
14 @SuppressWarnings("JavaDoc")
16 
17  @NotNull
18  private static final NamedGameObjectMatcher GAME_OBJECT_MATCHER1 = new NamedGameObjectMatcher(1, "i1", "f1", true, null, new TypeNrsGameObjectMatcher(1));
19 
20  @NotNull
21  private static final NamedGameObjectMatcher GAME_OBJECT_MATCHER2 = new NamedGameObjectMatcher(2, "i2", "f2", true, null, new TypeNrsGameObjectMatcher(2));
22 
23  @Test
24  public void encodeNamedFilter1() {
25  final NamedFilterConfig config = new NamedFilter(Collections.emptyList()).createConfig();
26  Assert.assertEquals("", new FilterConfigEncoder().encode(config));
27 
28  config.setEnabled(true);
29  Assert.assertEquals("(enabled)", new FilterConfigEncoder().encode(config));
30 
31  config.setInverted(true);
32  Assert.assertEquals("(enabled,inverted)", new FilterConfigEncoder().encode(config));
33 
34  config.setEnabled(false);
35  Assert.assertEquals("(inverted)", new FilterConfigEncoder().encode(config));
36  }
37 
38  @Test
40  final NamedGameObjectMatcherFilterConfig config = new NamedGameObjectMatcherFilter(GAME_OBJECT_MATCHER1).createConfig();
41  Assert.assertEquals("", new FilterConfigEncoder().encode(config));
42 
43  config.setEnabled(true);
44  Assert.assertEquals("(enabled)", new FilterConfigEncoder().encode(config));
45  }
46 
47  @Test
48  public void encodeSubFilterConfig1() {
49  final NamedFilterConfig config = new NamedFilter(Collections.singleton(GAME_OBJECT_MATCHER1)).createConfig();
50  Assert.assertEquals("", new FilterConfigEncoder().encode(config));
51 
52  config.setEnabled(true);
53  Assert.assertEquals("(enabled)", new FilterConfigEncoder().encode(config));
54 
55  config.setInverted(true);
56  Assert.assertEquals("(enabled,inverted)", new FilterConfigEncoder().encode(config));
57 
58  config.setEnabled(false);
59  Assert.assertEquals("(inverted)", new FilterConfigEncoder().encode(config));
60  }
61 
62  @Test
63  public void encodeSubFilterConfig2() {
64  final NamedFilterConfig config = new NamedFilter(Arrays.asList(GAME_OBJECT_MATCHER1, GAME_OBJECT_MATCHER2)).createConfig();
65  Assert.assertEquals("", new FilterConfigEncoder().encode(config));
66 
67  config.getConfig("f1").setEnabled(true);
68  Assert.assertEquals("(f1=(enabled))", new FilterConfigEncoder().encode(config));
69 
70  config.getConfig("f2").setEnabled(true);
71  Assert.assertEquals("(f1=(enabled),f2=(enabled))", new FilterConfigEncoder().encode(config));
72 
73  config.getConfig("f1").setEnabled(false);
74  Assert.assertEquals("(f2=(enabled))", new FilterConfigEncoder().encode(config));
75  }
76 
77 }
A Filter that aggregates named filters.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
void setEnabled(boolean enabled)
Enables or disables the filter.
A Filter which filters according to a net.sf.gridarta.model.match.NamedGameObjectMatcher.
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
Converts FilterConfig into string representation.
Base package of all Gridarta classes.
FilterConfig<?, ?> getConfig(@NotNull final String name)
Returns the FilterConfig for a sub-filter.
An GameObjectMatcher matching certain archetype types.
Filter configuration of NamedGameObjectMatcherFilter instances.
void setInverted(final boolean inverted)
Sets whether the filter should match if all sub-filters match or if at least one sub-filter does not ...