@Test public void atomCondition() { ArrangementAtomMatchCondition condition = new ArrangementAtomMatchCondition(FIELD); StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition); assertEquals(condition, matcher.getCondition()); final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field"); final TypeAwareArrangementEntry classEntry = myMockery.mock(TypeAwareArrangementEntry.class, "class"); final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public"); myMockery.checking(new Expectations() {{ allowing(fieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD))); allowing(classEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(CLASS))); allowing(publicEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC))); }}); assertTrue(matcher.isMatched(fieldEntry)); assertFalse(matcher.isMatched(classEntry)); assertFalse(matcher.isMatched(publicEntry)); }
@Test public void compositeAndCondition() { ArrangementCompositeMatchCondition condition = new ArrangementCompositeMatchCondition(); condition.addOperand(new ArrangementAtomMatchCondition(FIELD)); condition.addOperand(new ArrangementAtomMatchCondition(PUBLIC)); StdArrangementEntryMatcher matcher = new StdArrangementEntryMatcher(condition); assertEquals(condition, matcher.getCondition()); final TypeAwareArrangementEntry fieldEntry = myMockery.mock(TypeAwareArrangementEntry.class, "field"); final ModifierAwareArrangementEntry publicEntry = myMockery.mock(ModifierAwareArrangementEntry.class, "public"); final TypeAndModifierAware privateFieldEntry = myMockery.mock(TypeAndModifierAware.class, "private field"); final TypeAndModifierAware publicMethodEntry = myMockery.mock(TypeAndModifierAware.class, "public method"); final TypeAndModifierAware publicFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public field"); final TypeAndModifierAware publicStaticFieldEntry = myMockery.mock(TypeAndModifierAware.class, "public static field"); myMockery.checking(new Expectations() {{ allowing(fieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD))); allowing(publicEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC))); allowing(privateFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD))); allowing(privateFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PRIVATE))); allowing(publicMethodEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(METHOD))); allowing(publicMethodEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC))); allowing(publicFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD))); allowing(publicFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC))); allowing(publicStaticFieldEntry).getTypes(); will(returnValue(ContainerUtilRt.newHashSet(FIELD))); allowing(publicStaticFieldEntry).getModifiers(); will(returnValue(ContainerUtilRt.newHashSet(PUBLIC, STATIC))); }}); assertFalse(matcher.isMatched(fieldEntry)); assertFalse(matcher.isMatched(publicEntry)); assertFalse(matcher.isMatched(privateFieldEntry)); assertFalse(matcher.isMatched(publicMethodEntry)); assertTrue(matcher.isMatched(publicFieldEntry)); assertTrue(matcher.isMatched(publicStaticFieldEntry)); }
@Override public boolean isMatched(@NotNull ArrangementEntry entry) { if (entry instanceof ModifierAwareArrangementEntry) { final Set<ArrangementSettingsToken> modifiers = ((ModifierAwareArrangementEntry)entry).getModifiers(); for (ArrangementAtomMatchCondition condition : myModifiers) { final Object value = condition.getValue(); boolean isInverted = value instanceof Boolean && !((Boolean)value); if (isInverted == modifiers.contains(condition.getType())) { return false; } } return true; } return false; }
@Override public boolean isMatched(@NotNull ArrangementEntry entry) { if (entry instanceof ModifierAwareArrangementEntry) { return ((ModifierAwareArrangementEntry)entry).getModifiers().containsAll(myModifiers); } return false; }
@Override public boolean isMatched(@Nonnull ArrangementEntry entry) { if (entry instanceof ModifierAwareArrangementEntry) { final Set<ArrangementSettingsToken> modifiers = ((ModifierAwareArrangementEntry)entry).getModifiers(); for (ArrangementAtomMatchCondition condition : myModifiers) { final Object value = condition.getValue(); boolean isInverted = value instanceof Boolean && !((Boolean)value); if (isInverted == modifiers.contains(condition.getType())) { return false; } } return true; } return false; }