add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / src / test / org / apache / lucene / index / TestNoMergeScheduler.java
1 package org.apache.lucene.index;
2
3 /**
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 import java.lang.reflect.Constructor;
21 import java.lang.reflect.Method;
22 import java.lang.reflect.Modifier;
23 import java.util.Arrays;
24
25 import org.apache.lucene.util.LuceneTestCase;
26 import org.junit.Test;
27
28 public class TestNoMergeScheduler extends LuceneTestCase {
29
30   @Test
31   public void testNoMergeScheduler() throws Exception {
32     MergeScheduler ms = NoMergeScheduler.INSTANCE;
33     ms.close();
34     ms.merge(null);
35   }
36
37   @Test
38   public void testFinalSingleton() throws Exception {
39     assertTrue(Modifier.isFinal(NoMergeScheduler.class.getModifiers()));
40     Constructor<?>[] ctors = NoMergeScheduler.class.getDeclaredConstructors();
41     assertEquals("expected 1 private ctor only: " + Arrays.toString(ctors), 1, ctors.length);
42     assertTrue("that 1 should be private: " + ctors[0], Modifier.isPrivate(ctors[0].getModifiers()));
43   }
44
45   @Test
46   public void testMethodsOverridden() throws Exception {
47     // Ensures that all methods of MergeScheduler are overridden. That's
48     // important to ensure that NoMergeScheduler overrides everything, so that
49     // no unexpected behavior/error occurs
50     for (Method m : NoMergeScheduler.class.getMethods()) {
51       // getDeclaredMethods() returns just those methods that are declared on
52       // NoMergeScheduler. getMethods() returns those that are visible in that
53       // context, including ones from Object. So just filter out Object. If in
54       // the future MergeScheduler will extend a different class than Object,
55       // this will need to change.
56       if (m.getDeclaringClass() != Object.class) {
57         assertTrue(m + " is not overridden !", m.getDeclaringClass() == NoMergeScheduler.class);
58       }
59     }
60   }
61
62 }