1. Project Clover database mar. avr. 16 2024 08:19:06 CEST
  2. Package org.devacfr.testing.jupiter

File ParserTestCase.java

 

Coverage histogram

../../../../img/srcFileCovDistChart4.png
81% of files have more coverage

Code metrics

2
19
17
1
162
74
18
0,95
1,12
17
1,06

Classes

Class Line # Actions
ParserTestCase 50 19 0% 18 26
0.3157894631,6%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing,
13    * software distributed under the License is distributed on an
14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15    * KIND, either express or implied. See the License for the
16    * specific language governing permissions and limitations
17    * under the License.
18    */
19    package org.devacfr.testing.jupiter;
20   
21    import javax.annotation.Nonnull;
22    import javax.annotation.Nullable;
23   
24    import java.nio.file.Path;
25    import java.nio.file.Paths;
26    import java.util.function.Function;
27   
28    import com.google.common.io.ByteSource;
29    import com.google.common.io.Resources;
30    import org.apache.maven.doxia.parser.AbstractParserTest;
31    import org.devacfr.testing.util.Approvals;
32    import org.junit.jupiter.api.BeforeEach;
33    import org.junit.jupiter.api.TestInfo;
34   
35    /*
36    * Copyright 2012-2019 Christophe Friederich
37    *
38    * Licensed under the Apache License, Version 2.0 (the "License");
39    * you may not use this file except in compliance with the License.
40    * You may obtain a copy of the License at
41    *
42    * http://www.apache.org/licenses/LICENSE-2.0
43    *
44    * Unless required by applicable law or agreed to in writing, software
45    * distributed under the License is distributed on an "AS IS" BASIS,
46    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
47    * See the License for the specific language governing permissions and
48    * limitations under the License.
49    */
 
50    public abstract class ParserTestCase extends AbstractParserTest {
51   
52    private TestInfo testInfo;
53   
 
54  4 toggle @BeforeEach
55    public final void beforeEachMethod(final TestInfo testInfo) {
56  4 this.testInfo = testInfo;
57    }
58   
 
59  0 toggle public String getName() {
60  0 return this.getClass().getSimpleName();
61    }
62   
63    /**
64    * Gets the file system path representation of this test class.
65    *
66    * @return Returns {@code String} representing the file system location path of this test class.
67    */
 
68  2 toggle @Nonnull
69    public final Path getPackagePath() {
70  2 return Paths.get(getPackagePath(this.getClass()));
71    }
72   
 
73  0 toggle public ByteSource getResource(final String filename) {
74  0 return Resources.asByteSource(Resources.getResource(getPackagePath().resolve(filename).toString()));
75    }
76   
77    /**
78    * Gets the file system path representation of this test class.
79    *
80    * @param testClass
81    * test class to use.
82    * @return Returns {@code String} representing the file system location path of this test class.
83    */
 
84  2 toggle @Nonnull
85    public static final String getPackagePath(@Nonnull final Class<?> testClass) {
86  2 return testClass.getPackage().getName().replace('.', '/');
87    }
88   
 
89  0 toggle public String getActualResource() {
90  0 return Approvals.getActualResource(getPackagePath(), this.getClass(), getMethodName(), null);
91    }
92   
 
93  0 toggle public String getExpectedResource() {
94  0 return Approvals.getExpectedResource(getPackagePath(), this.getClass(), getMethodName(), null, null);
95    }
96   
 
97  0 toggle public String getActualResource(final String extension) {
98  0 return Approvals.getActualResource(getPackagePath(), this.getClass(), getMethodName(), extension);
99    }
100   
 
101  0 toggle public String getExpectedResource(final String extension) {
102  0 return Approvals.getExpectedResource(getPackagePath(), this.getClass(), getMethodName(), extension, null);
103    }
104   
 
105  0 toggle public String getExpectedResource(final String extension, final Function<String, String> transformer) {
106  0 return Approvals
107    .getExpectedResource(getPackagePath(), this.getClass(), getMethodName(), extension, transformer);
108    }
109   
 
110  0 toggle public void verify() {
111  0 Approvals.verify(getPackagePath(), this.getClass(), getMethodName(), (Function<String, String>) null, null);
112    }
113   
114    /**
115    * @param extension
116    * the extension file.
117    */
 
118  0 toggle public void verify(final String extension) {
119  0 Approvals
120    .verify(getPackagePath(), this.getClass(), getMethodName(), (Function<String, String>) null, extension);
121    }
122   
 
123  0 toggle public void verify(final Function<String, String> transform) {
124  0 Approvals.verify(getPackagePath(), this.getClass(), getMethodName(), transform, null);
125    }
126   
127    /**
128    * @param transform
129    * @param extension
130    * the extension file.
131    */
 
132  2 toggle public void verify(final Function<String, String> transform, @Nullable final String extension) {
133  2 Approvals.verify(getPackagePath(), this.getClass(), getMethodName(), transform, extension);
134    }
135   
136    /**
137    * @param actual
138    * the actual value to test.
139    * @param extension
140    * the extension file.
141    */
 
142  0 toggle public void verify(@Nullable final String actual, @Nullable final String extension) {
143  0 Approvals.verify(getPackagePath(), this.getClass(), getMethodName(), actual, extension);
144    }
145   
146    /**
147    * @param actualFile
148    * the actual value stored in file to test.
149    * @param extension
150    * the extension file.
151    */
 
152  0 toggle public void verify(@Nonnull final Path actualFile, @Nullable final String extension) {
153  0 Approvals.verify(getPackagePath(), this.getClass(), getMethodName(), actualFile, extension);
154    }
155   
 
156  2 toggle private String getMethodName() {
157  2 if (testInfo == null) {
158  0 return null;
159    }
160  2 return this.testInfo.getTestMethod().get().getName();
161    }
162    }