Coverage Report - com.jcabi.dynamo.mock.MkTable
 
Classes in this File Line Coverage Branch Coverage Complexity
MkTable
61%
11/18
0%
0/20
1.333
MkTable$AjcClosure1
100%
1/1
N/A
1.333
MkTable$AjcClosure3
100%
1/1
N/A
1.333
MkTable$AjcClosure5
0%
0/1
N/A
1.333
MkTable$AjcClosure7
0%
0/1
N/A
1.333
MkTable$AjcClosure9
0%
0/1
N/A
1.333
 
 1  4
 /**
 2  
  * Copyright (c) 2012-2016, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.dynamo.mock;
 31  
 
 32  
 import com.amazonaws.services.dynamodbv2.model.AttributeValue;
 33  
 import com.jcabi.aspects.Immutable;
 34  
 import com.jcabi.aspects.Loggable;
 35  
 import com.jcabi.dynamo.Attributes;
 36  
 import com.jcabi.dynamo.Frame;
 37  
 import com.jcabi.dynamo.Item;
 38  
 import com.jcabi.dynamo.Region;
 39  
 import com.jcabi.dynamo.Table;
 40  
 import java.io.IOException;
 41  
 import java.util.Map;
 42  
 import lombok.EqualsAndHashCode;
 43  
 import lombok.ToString;
 44  
 
 45  
 /**
 46  
  * Mock version of {@link Table}.
 47  
  *
 48  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 49  
  * @version $Id: aea24468945f210bc3f5c79f7cf3650d3b19b2a6 $
 50  
  * @since 0.10
 51  
  */
 52  
 @Immutable
 53  2
 @ToString
 54  
 @Loggable(Loggable.DEBUG)
 55  0
 @EqualsAndHashCode(of = { "self", "data" })
 56  
 final class MkTable implements Table {
 57  
 
 58  
     /**
 59  
      * Data.
 60  
      */
 61  
     private final transient MkData data;
 62  
 
 63  
     /**
 64  
      * Name of the table.
 65  
      */
 66  
     private final transient String self;
 67  
 
 68  
     /**
 69  
      * Public ctor.
 70  
      * @param name Name of the table
 71  
      * @param dta Data
 72  
      */
 73  2
     MkTable(final MkData dta, final String name) {
 74  2
         this.data = dta;
 75  2
         this.self = name;
 76  2
     }
 77  
 
 78  
     @Override
 79  
     public Item put(final Map<String, AttributeValue> attributes) {
 80  4
         final Attributes attrs = new Attributes(attributes);
 81  
         try {
 82  2
             this.data.put(this.self, attrs);
 83  0
         } catch (final IOException ex) {
 84  0
             throw new IllegalStateException(ex);
 85  2
         }
 86  2
         return new MkItem(this.data, this.self, attrs);
 87  
     }
 88  
 
 89  
     @Override
 90  
     public Frame frame() {
 91  4
         return new MkFrame(this.data, this.self);
 92  
     }
 93  
 
 94  
     @Override
 95  
     public Region region() {
 96  0
         return new MkRegion(this.data);
 97  
     }
 98  
 
 99  
     @Override
 100  
     public String name() {
 101  0
         return this.self;
 102  
     }
 103  
 
 104  
     @Override
 105  
     public void delete(final Map<String, AttributeValue> attributes)
 106  
         throws IOException {
 107  0
         this.data.delete(
 108  
             this.self,
 109  
             new Attributes(attributes)
 110  
         );
 111  0
     }
 112  
 }