1
package org.apache.lucene.index;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
import java.lang.reflect.Constructor;
21
import java.lang.reflect.Method;
22
import java.lang.reflect.Modifier;
23
import java.util.Arrays;
25
import org.apache.lucene.util.LuceneTestCase;
26
import org.junit.Test;
28
public class TestNoMergePolicy extends LuceneTestCase {
31
public void testNoMergePolicy() throws Exception {
32
MergePolicy mp = NoMergePolicy.NO_COMPOUND_FILES;
33
assertNull(mp.findMerges(null));
35
//assertNull(mp.findMergesToExpungeDeletes(null));
36
assertFalse(mp.useCompoundFile(null, null));
41
public void testCompoundFiles() throws Exception {
42
assertFalse(NoMergePolicy.NO_COMPOUND_FILES.useCompoundFile(null, null));
43
assertTrue(NoMergePolicy.COMPOUND_FILES.useCompoundFile(null, null));
47
public void testFinalSingleton() throws Exception {
48
assertTrue(Modifier.isFinal(NoMergePolicy.class.getModifiers()));
49
Constructor<?>[] ctors = NoMergePolicy.class.getDeclaredConstructors();
50
assertEquals("expected 1 private ctor only: " + Arrays.toString(ctors), 1, ctors.length);
51
assertTrue("that 1 should be private: " + ctors[0], Modifier.isPrivate(ctors[0].getModifiers()));
55
public void testMethodsOverridden() throws Exception {
56
// Ensures that all methods of MergePolicy are overridden. That's important
57
// to ensure that NoMergePolicy overrides everything, so that no unexpected
58
// behavior/error occurs
59
for (Method m : NoMergePolicy.class.getMethods()) {
60
// getDeclaredMethods() returns just those methods that are declared on
61
// NoMergePolicy. getMethods() returns those that are visible in that
62
// context, including ones from Object. So just filter out Object. If in
63
// the future MergePolicy will extend a different class than Object, this
64
// will need to change.
65
if (m.getDeclaringClass() != Object.class) {
66
assertTrue(m + " is not overridden !", m.getDeclaringClass() == NoMergePolicy.class);