Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.nikolavp.approval.pathmappers;
  * #%L
  * approval
  * %%
  * Copyright (C) 2014 Nikolavp
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
import  javax.annotation.Nonnull;
import  javax.annotation.Nullable;
A path mapper that will put all approvals in a common parent path. Let's say you want to put all your approval results in src/test/resources/approval(we assume a common maven directory structure) then you can use this mapper as follows:

Approval approval = Approval.of(String.class)
  .withPathMapper(new ParentPathMapper(Paths.get("src/test/resources/approval")))

now the following call

approval.verify("Some cool string value", Paths.get("some_cool_value.txt");

will put the approved value in the file src/test/resources/approval/some_cool_value.txt

<T> the value that will be approved
public class ParentPathMapper<T> implements PathMapper<T> {
    private final Path parentPath;

Creates a parent path mapper that puts approvals in the given parent path.

parentPath the parent path for all approvals
    public ParentPathMapper(Path parentPath) {
        this. = parentPath;
    public Path getPath(@Nullable T valuePath approvalFilePath) {
        return .resolve(approvalFilePath);
New to GrepCode? Check out our FAQ X