Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

TestAbstractFunctionPtg.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.ss.formula.ptg;
  16. import static org.junit.jupiter.api.Assertions.assertEquals;
  17. import static org.junit.jupiter.api.Assertions.assertThrows;
  18. import org.apache.poi.util.LittleEndianOutput;
  19. import org.junit.jupiter.api.Test;
  20. class TestAbstractFunctionPtg {
  21. @Test
  22. void testConstructor() {
  23. FunctionPtg ptg = new FunctionPtg(1, 2, null, 255);
  24. assertEquals(1, ptg.getFunctionIndex());
  25. assertEquals(2, ptg.getDefaultOperandClass());
  26. assertEquals(255, ptg.getNumberOfOperands());
  27. }
  28. @Test
  29. void testInvalidFunctionIndex() {
  30. assertThrows(RuntimeException.class, () -> new FunctionPtg(40000, 2, null, 255));
  31. }
  32. @Test
  33. void testInvalidRuntimeClass() {
  34. assertThrows(RuntimeException.class, () -> new FunctionPtg(1, 300, null, 255));
  35. }
  36. private static class FunctionPtg extends AbstractFunctionPtg {
  37. protected FunctionPtg(int functionIndex, int pReturnClass,
  38. byte[] paramTypes, int nParams) {
  39. super(functionIndex, pReturnClass, paramTypes, nParams);
  40. }
  41. @Override
  42. public byte getSid() {
  43. return -1;
  44. }
  45. public int getSize() {
  46. return 0;
  47. }
  48. public void write(LittleEndianOutput out) {
  49. }
  50. @Override
  51. public FunctionPtg copy() {
  52. // immutable
  53. return this;
  54. }
  55. }
  56. }